- Technically, a thread is defined as an independent stream of instructions that can be scheduled to run by the operating system (OS).
- Suppose that a main program (a.out) that contains a number of procedures.
- Then suppose all of these procedures being able to be scheduled to run simultaneously and/or independently.
- That would describe a ``multi-threaded'' program.
- Before understanding a thread, one first needs to understand a UNIX process.
- Processes contain information about program resources and program execution state.
Figure 6.1:
Left: Unix process. Right: Threads within a Unix process.
|
- Threads use and exist within these process resources,
- To be scheduled by the OS,
- Run as independent entities.
- This independent flow of control is accomplished because a thread maintains its own:
- Stack pointer
- Registers
- Scheduling properties (such as policy or priority)
- Set of pending and blocked signals
- Thread specific data.
- A thread has its own independent flow of control as long as its parent process exists (dies if the parent process dies!).
- A thread duplicates only the essential resources it needs.
- A thread is "lightweight" because most of the overhead has already been accomplished through the creation of its process.
Cem Ozdogan
2010-12-27