Information Technology Reference
In-Depth Information
Example: Hybrid thread join. As a simple example, rather than always hav-
ing threadjoin() make a system call to wait for the target thread to finish and
return its exit value, we can have threadexit() store its exit value in a data
structure in the process's address space. Then, if the call to threadjoin()
happens after the targeted has exited, it can immediately return that stored
value without having to make a system call and mode switch into the kernel.
However, if the call to threadjoin() preceeds the call to threadexit() , then
the call to threadexit() would make a system call to transition to the W AIT -
ING state and let some other thread run.
Example: Scheduler activations. A more sophisticated example is sched-
uler activations. Like the full user-level threads package described at the
start of this sidebar, a thread system based on scheduler activations main-
tains its ready list and other data structures within the process and handles
most thread management functions— threadcreate() , threaddestroy() ,
threadyield() , threadexit() , and threadjoin() , as well as the synchro-
nization functions described in the next chapter—as procedure calls within the
process.
Scheduler ativations address the two problems noted above for pure user-level
threads packages: they allow a process to run multiple threads in parallel on a
multiprocessor, and they allow a process to hide I/O latency by running other
threads when one thread blocks for I/O.
Scheduler activations solve these problems by allowing the kernel to activate
the user-level scheduler when it wants to start running another one of the pro-
cess's threads. Initially, the process does a system call to register its scheduler
with the kernel; this is similar to registering a signal handler. Then, if the kernel
is running on a multiprocessor machine and notices that a processor is avail-
able or if one of the process's threads blocks in a system call, the kernel can
activate the process's scheduler in a way similar to how it would invoke a signal
handler. The user-level scheduler ativation code can then transition to running
any of the process's R EADY threads.
Exercises
11. Using sthreads, write a program that creates several threads and that then
determines whether the threads package on your system allocates a fixed
size stack for each thread or whether each thread's stack starts at some
small size and dynamically grows as needed.
Hints: You will probably want to write a recursive procedure that you
can use to consume a large amount of stack memory. You may also want
Search WWH ::




Custom Search