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 > Synchronization Primitives

Synchronization Primitives

Synchronization is used to coordinate the activity of multiple threads. There are various situations where it is necessary; this might be to ensure that shared resources are not accessed by multiple threads simultaneously or that all work on those resources is complete before new work starts.

Most operating systems provide a rich set of synchronization primitives. It is usually most appropriate to use these rather than attempting to write custom methods of synchronization. There are two reasons for this. Synchronization primitives provided by the operating system will usually be recognized by the tools provided with that operating system. Hence, the tools will be able to do a better job of detecting data races or correctly labeling synchronization costs. The operating system will often provide support for sharing the primitives between threads or processes, which can be hard to do efficiently without operating system support. However, the most critical consideration is that the code provided by the operating system is unlikely to contain bugs. Discussion of writing custom synchronization primitives is covered in Chapter 8, “Hand-Coded Synchronization and Sharing.”


  

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