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 4. Synchronization and Data Sharing > Storing Thread-Private Data

Storing Thread-Private Data

A single-threaded application might use global data to hold program state. For example, a single-threaded word processor might have global variables that hold the name of the document being edited or the current line number.

In a multithreaded application, it is sometimes necessary for each thread to hold some state. This state is private to the thread but can be accessed by all the code that the thread executes. Returning to the word processor example, if it opens multiple documents and each document is handled by a single thread, then each thread will want to have a separate variable to hold the name of the document and the current line number. This data would be private to each thread—no other thread could read it. The application may still have some global state—perhaps it records details of the person using it—and all threads would have access to this same information.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free Trial


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