#include <thread.h>
Public Methods | |
| Thread (char *debugName) | |
| initialize a Thread. More... | |
| ~Thread () | |
| deallocate a Thread NOTE -- thread being deleted must not be running when delete is called. More... | |
| void | Fork (VoidFunctionPtr func, void *arg) |
| Make thread run (*func)(arg). More... | |
| void | Yield () |
| Relinquish the CPU if any other thread is runnable. More... | |
| void | Sleep (bool finishing) |
| Put the thread to sleep and relinquish the processor. More... | |
| void | Begin () |
| Startup code for the thread. More... | |
| void | Finish () |
| The thread is done executing. More... | |
| void | CheckOverflow () |
| Check if thread stack has overflowed. More... | |
| void | setStatus (ThreadStatus st) |
| char* | getName () |
| void | Print () |
| void | SelfTest () |
| test whether thread impl is working. More... | |
Private Methods | |
| void | StackAllocate (VoidFunctionPtr func, void *arg) |
| Allocate a stack for thread. Used internally by Fork(). More... | |
Private Attributes | |
| int* | stackTop |
| the current stack pointer. More... | |
| void* | machineState [MachineStateSize] |
| all registers except for stackTop. More... | |
| int* | stack |
| Bottom of the stack NULL if this is the main thread (If NULL, don't deallocate stack). More... | |
| ThreadStatus | status |
| ready, running or blocked. More... | |
| char* | name |
Definition at line 79 of file thread.h.
|
|
initialize a Thread. Thread::Thread Initialize a thread control block, so that we can then call Thread::Fork. "threadName" is an arbitrary string, useful for debugging. Definition at line 36 of file thread.cc. Referenced by SelfTest().
|
|
|
deallocate a Thread NOTE -- thread being deleted must not be running when delete is called. Thread::~Thread De-allocate a thread. NOTE: the current thread *cannot* delete itself directly, since it is still running on the stack that we need to delete. NOTE: if this is the main thread, we can't delete the stack because we didn't allocate it -- we got it automatically as part of starting up Nachos. |
|
|
Startup code for the thread. Thread::Begin Called by ThreadRoot when a thread is about to begin executing the forked procedure. It's main responsibilities are: 1. deallocate the previously running thread if it finished (see Thread::Finish()) 2. enable interrupts (so we can get time-sliced) |
|
|
Check if thread stack has overflowed. Thread::CheckOverflow Check a thread's stack to see if it has overrun the space that has been allocated for it. If we had a smarter compiler, we wouldn't need to worry about this, but we don't. NOTE: Nachos will not catch all stack overflow conditions. In other words, your program may still crash because of an overflow. If you get bizarre results (such as seg faults where there is no code) then you *may* need to increase the stack size. You can avoid stack overflows by not putting large data structures on the stack. Don't do this: void foo() { int bigArray[10000]; ... } |
|
|
The thread is done executing. Thread::Finish Called by ThreadRoot when a thread is done executing the forked procedure. NOTE: we can't immediately de-allocate the thread data structure or the execution stack, because we're still running in the thread and we're still on the stack! Instead, we tell the scheduler to call the destructor, once it is running in the context of a different thread. NOTE: we disable interrupts, because Sleep() assumes interrupts are disabled. Definition at line 178 of file thread.cc. Referenced by ThreadedKernel::Run().
|
|
|
Make thread run (*func)(arg). Thread::Fork Invoke (*func)(arg), allowing caller and callee to execute concurrently. NOTE: although our definition allows only a single argument to be passed to the procedure, it is possible to pass multiple arguments by making them fields of a structure, and passing a pointer to the structure as "arg". Implemented as the following steps: 1. Allocate a stack 2. Initialize the stack so that a call to SWITCH will cause it to run the procedure 3. Put the thread on the ready queue "func" is the procedure to run concurrently. "arg" is a single argument to be passed to the procedure. Definition at line 97 of file thread.cc. Referenced by ElevatorSelfTest(), PostOfficeInput::PostOfficeInput(), SelfTest(), SynchList::SelfTest(), and Semaphore::SelfTest().
|
|
|
Definition at line 107 of file thread.h. Referenced by ThreadPrint().
|
|
|
test whether thread impl is working. Thread::SelfTest Set up a ping-pong between two threads, by forking a thread to call SimpleThread, and then calling SimpleThread ourselves. Definition at line 438 of file thread.cc. Referenced by ThreadedKernel::SelfTest().
|
|
|
Put the thread to sleep and relinquish the processor. Thread::Sleep Relinquish the CPU, because the current thread has either finished or is blocked waiting on a synchronization variable (Semaphore, Lock, or Condition). In the latter case, eventually some thread will wake this thread up, and put it back on the ready queue, so that it can be re-scheduled. NOTE: if there are no threads on the ready queue, that means we have no thread to run. "Interrupt::Idle" is called to signify that we should idle the CPU until the next I/O interrupt occurs (the only thing that could cause a thread to become ready to run). NOTE: we assume interrupts are already disabled, because it is called from the synchronization routines which must disable interrupts for atomicity. We need interrupts off so that there can't be a time slice between pulling the first thread off the ready list, and switching to it. Definition at line 247 of file thread.cc. Referenced by Finish(), and Semaphore::P().
|
|
|
Allocate a stack for thread. Used internally by Fork(). Thread::StackAllocate Allocate and initialize an execution stack. The stack is initialized with an initial stack frame for ThreadRoot, which: enables interrupts calls (*func)(arg) calls Thread::Finish "func" is the procedure to be forked "arg" is the parameter to be passed to the procedure Definition at line 316 of file thread.cc. Referenced by Fork().
|
|
|
Relinquish the CPU if any other thread is runnable. Thread::Yield Relinquish the CPU if any other thread is ready to run. If so, put the thread on the end of the ready list, so that it will eventually be re-scheduled. NOTE: returns immediately if no other thread on the ready queue. Otherwise returns when the thread eventually works its way to the front of the ready list and gets re-scheduled. NOTE: we disable interrupts, so that looking at the thread on the front of the ready list, and switching to it, can be done atomically. On return, we re-set the interrupt level to its original state, in case we are called with interrupts disabled. Similar to Thread::Sleep(), but a little different. |
|
|
Definition at line 106 of file thread.h. Referenced by Scheduler::ReadyToRun().
|
|
|
Definition at line 105 of file thread.h. Referenced by ThreadedKernel::Initialize(), and Scheduler::ReadyToRun().
|
|
|
all registers except for stackTop.
|
|
|
|
|
|
Bottom of the stack NULL if this is the main thread (If NULL, don't deallocate stack).
|
|
|
the current stack pointer.
|
|
|
ready, running or blocked.
|
1.2.8.1 written by Dimitri van Heesch,
© 1997-2001