Information Technology Reference
In-Depth Information
Shared
Per−Thread
State
Per−Thread
State
State
Thread Control
Block (TCB)
Thread Control
Block (TCB)
Heap
Stack
Information
Stack
Information
Saved
Registers
Saved
Registers
Global
Variables
Thread
Metadata
Thread
Metadata
Stack
Stack
Code
Figure4.8: A multi-threaded process or operating system's state is divided
intoperthreadstateandsharedstate. The thread control block is the object
that stores per-thread state. The per-thread state includes the state needed
to represent the thread's computation (e.g., the processor registers, the stack,
and thread-local variables.) The per-thread state also included metadata|
data about the thread used by the operating system in managing the thread
(e.g., the thread's ID, scheduling priority, owner, and resource consumption.) In
addition to per-thread state, a multi-threaded process (or the operating system
kernel) includes shared state, shared by all threads running in that process (or
kernel). For example, this shared state includes the program's code, global
static variables, and the heap.
and bar() calls bas() , then the stack would contain a stack frame for each
of these three proceedures, and each stack frame might contain the local
variables used by the procedure, the parameters the procedure was called
with, and the return address to jump to when the procedure completes.
Because at any given time, each thread can be in a different state in
its sequential computation|it can be in a dierent place in a dierent
procedure called with different arguments from a different nesting of en-
closing procedures|each thread needs its own stack. Typically, when a
new thread is created, a new stack is allocated for it, and a pointer to that
stack is stored in the thread's TCB.
2. Copy of processor registers. A processor's registers include not only
general purpose registers for storing values for ongoing computations but
also special purpose registers like the instruction pointer and stack pointer.
Because the operating system needs to be able to suspend a thread, run
another thread, and then later resume the original thread, the operating
 
Search WWH ::




Custom Search