Information Technology Reference
In-Depth Information
the value of that counter is divisible by 10,000,000. The second thread
repeatedly waits for the user to input a line of text and then prints \Thank
you for your input." On your system, does the operating system do a good
job of making sure that the first thread makes rapid progress and that the
second thread responds quickly?
6. Write a program that performs a parallel matrix multiply...
4.3
Thread internals
Each thread represents a sequential stream of execution, and the operating
system provides the illusion that each thread runs on its own virtual processor
by transparently suspending and resuming threads.
To understand how the operating system implements the threads abstrac-
tion, we must define the state needed to represent a thread. Then, we can
understand a thread's lifecycle|how the operating system can create, start,
stop, and delete threads to provide the abstraction.
4.3.1
Thread control block (TCB) and per-thread state
The operating system needs a data structure to represent a thread's state; a
thread is like any other object in this regard. The data structure that hold the
thread's state is called the thread control block (TCB). For every thread the
Definition: thread control
block (TCB)
operating system creates, it will create one TCB.
A thread's TCB holds two types of information:
The state of the computation being performed by the thread
Metadata about the thread that is used to manage the thread
Per-thread computation state. Each thread represents its own sequentially-
executed computation, so to create multiple threads, we must allocate per-
thread state to represent the current state of each thread's computation. Each
thread's TCB therefore contains two elements of per-thread computation state:
1. Stack.
A thread's stack is the same as the stack for a single-threaded computation|
it stores information needed by the nested procedures the thread is cur-
rently running. For example, if a thread calls foo() , foo() calls bar() ,
Search WWH ::




Custom Search