Information Technology Reference
In-Depth Information
Kernel Thread 1
Kernel Thread 1
Kernel Thread 1
Process 1
Process 2
Exception
Stack
Globals
Kernel
TCB 1
TCB 1
TCB 1
PCB 1,1
PCB 2,1
Heap
PCB 1,2
PCB 2,2
Stack
Stack
Stack
Code
Process 1
Process 2
Thread 1
Thread 2
Thread 1
Thread 2
User-Level Processes
Stack
Stack
Stack
Stack
Globals
Heap
Code
Globals
Heap
Code
Figure4.15: A multi-threaded kernel with 3 kernel threads and 2 user-level processes, each with 2
threads.
Multi-threaded kernel with multi-threaded processes
The basic infrastructure just described for running a mix of kernel threads and
single-threaded user processes needs little change to run mulit-threaded user
processes such as the mix shown in Figure ??. The kernel's ready list includes
kernel thread TCBs and one or more PCBs for each user-level process, and the
thread context switch mechanisms work as described in the previous subsection
to allow switching between kernel threads, between a kernel thread and a process
thread, between threads from different processes, or between threads from the
same process.
A process can now use system calls to create multiple threads. Notice that
for each thread, the thread's PCB is created in the kernel, but the thread's
stack is allocated in the process's memory. But, the process's threads share
other state such as the process's code, heap, and globals.
A process can create multiple threads for the reasons listed at the start of
the chapter.
1. Program structure. A program that needs to do multiple things at
the same time can create a thread for each one and rely on the operating
system to transparently switch among these threads so that each makes
progress.
2. Exploiting multiple processors. If a program can divide its work into
independent pieces, it can create a thread for each piece. If multiple
processors are available|this depends on what hardware the program is
running on and on what other kernel threads and other processes are
Search WWH ::




Custom Search