Information Technology Reference
In-Depth Information
Logical View
Thread 1
Thread 2
while(1) f
while(1) f
thread yield()
thread yield()
g
g
Physical Reality
Thread 1's instructions
Thread 2's instructions
Processor's instructions
call thread yield
call thread yield
save state to stack
save state to stack
save state to TCB
save state to TCB
choose another thread
choose another thread
load other thread state
load other thread state
call thread yield
call thread yield
save state to stack
save state to stack
save state to TCB
save state to TCB
choose another thread
choose another thread
load other thread state
load other thread state
return thread yield
return thread yield
call thread yield
call thread yield
save state to stack
save state to stack
save state to TCB
save state to TCB
choose another thread
choose another thread
load other thread state
load other thread state
return thread yield
return thread yield
call thread yield
call thread yield
save state to stack
save state to stack
save state to TCB
save state to TCB
choose another thread
choose another thread
load other thread state
load other thread state
return thread yield
return thread yield
...
...
...
Figure4.13: Interleaving of instructions when two threads loop and call
threadyield() .
4.4.4
Multi-threaded processes
So far, we have described how to implement multiple threads in a kernel.
Threads are also a useful abstraction for applications, so modern operating
systems support multi-threaded processes.
We will describe how operating systems provide the abstraction of multi-
threaded processes in two
steps.
First, we will describe how single-threaded processes mesh with the mech-
anisms we've just described for implementing a multi-threaded operating
system.
Then, we will describe a few small additions needed to support multi-
threaded processes.
 
Search WWH ::




Custom Search