Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Thread-local storage enables each thread in an application to store private copies of data. Each thread accesses the data in the same way but cannot see the values held by other threads. In essence, it is “global” data that has scope limited to the executing thread.
There are two approaches to thread-local storage. The easiest approach is to use the __declspec(thread) specifier to allocate a thread-local variable. Listing 6.38 shows an example of this. In this code, each thread holds the value passed into it in a thread-local variable.