All parts of the process structure are in kernel space (Figure 2-4). A user program cannot touch
any of that data directly. By contrast, all of the user code (functions, procedures, etc.), along with
the data, is in user space and can be accessed directly.
Figure 2-4. Relationship between a Process and Threads
A thread is a lightweight entity, comprising the registers, stack, and some other data. The rest of
the process structure is shared by all threads: the address space, file descriptors, etc. Much (and
sometimes all) of the thread structure is in user space, allowing for very fast access.
The actual code (functions, routines, signal handlers, etc.) is global, and it can be executed on any
thread. In Figure 2-4 we show three threads (T1, T2, and T3), along with their stacks, stack
pointers (SP), and program counters (PC). T1 and T2 are executing the same function. This is a
normal situation, just as two different people can read the same road sign at the same time.
All threads in a process share the state of that process (Figure 2-5). They reside in exactly the
same memory space, see the same functions, and see the same data. When one thread alters a
process variable (say, the working directory), all the others will see the change when they next
access it. If one thread opens a file to read it, all the other threads can also read from it.
From here on, we will use the squiggle shown in the figure to represent the entire thread--stack,
stack pointer, program counter, thread structure, etc.
Figure 2-5. Process Structure and Thread Structures
Search WWH :