Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. Windows Threading > Allocating Thread-Local Storage

Allocating Thread-Local Storage

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.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint