Chapter 8. Thread Synchronization
Threads can simplify program design and implementation and also improve performance, but thread usage requires care to ensure that shared resources are protected against simultaneous modification and that threads run only when requested or required. This chapter shows how to use Windows' synchronization objectsCRITICAL_SECTIONs, mutexes, semaphores, and eventsto solve these problems and describes some of the problems, such as deadlocks and race conditions, that can occur when the synchronization objects are not used properly. Synchronization objects can be used to synchronize threads in the same process or in separate processes.The examples illustrate the synchronization objects and discuss the performance impacts, both positive and negative, of different synchronization methods. The following chapters then show how to use synchronization to solve additional programming problems, improve performance, avoid pitfalls, and use more advanced features.Thread synchronization is a fundamental and interesting topic, and it is essential in nearly all threaded applications. Nonetheless, readers who are primarily interested in interprocess communication, network programming, and building threaded servers can skip to Chapter 11 and return to 10 for background material as required.
