Information Technology Reference
In-Depth Information
7. For the threadHello program in Figure ??, when pthreadjoin() returns
for thread ii , in which of the states shown in Figure 4.9 is thread ii ?
8. For the threadHello program in Figure ?? the procedure go() has the
parameter np and the local variable n . Are these variables per thread or
shared state? Where does the compiler store these variables' states?
9. For the threadHello program in Figure ?? the procedure main() has local
variables such as ii , err , ane status . Are these variables per thread or
shared state? Where does the compiler store these variables' states?
10. In the sidebar on page 151, we describe thread-local variables, which are
another piece of per-thread state present in many thread systems.
Describe how you would implement thread-local variables. Each thread
should have an array of 1024 pointers to its thread-local variables.
What would you add to the TCB?
How would you change the thread creation procedure? (For simplic-
ity, assume that when a thread is created, all 1024 entries should be
initialized to NULL.)
How would a running thread allocate a new thread-local variable?
In you design, how would a running thread access a particular thread-
local variable?
4.4
Implementation details
In the discussion above, we sketched the basic operation of threads. To make
things concrete, we now describe how to implement threads in more detail.
Types of threads. Operating systems use threads internally|the operating
system kernel can be multi-threaded|and they also provide the abstraction of
threads to user-level processes so that processes can be multi-threaded.
The implementation of these two cases is almost identical. For simplicity we
initially focus on how to implement in-kernel threads. This case is the simplest
one because all of the scheduling and thread-switching actions occur in one
place|the kernel. We will then discuss the small changes needed to extend the
threads abstraction to support multi-threaded processes.
Search WWH ::




Custom Search