Thread Basics
Figure 6-1 in the previous chapter shows how threads exist in a process environment. Chapter 11.
Figure 7-1. Threads in a Server Environment
[View full size image]

- Each thread has its own stack for use in function calls and other processing.
- The calling process can pass an argument (Arg in Figure 7-1), usually a pointer, to a thread at creation time. This argument is actually on the thread's stack.
- Each thread can allocate its own Thread Local Storage (TLS) indexes and read and set TLS values. TLS, described later, provides small data arrays to threads, and a thread can access only its own TLS array. Among other advantages, TLS assures that threads will not modify one another's data.
The thread argumentor, alternatively, TLScan be used to point to an arbitrary data structure. In Figure 7-1's server example, this structure might contain the current request and the thread's response to that request as well as other working storage.Windows exploits SMP systems by allowing different threads, even from the same process, to run concurrently on separate processors. This capability, if used properly, can enhance performance, but without sufficient care and a good strategy to exploit multiple processors, execution on an SMP system can actually be slower than on a single-processor system, as we'll see in the next two chapters.