Chapter 9. Synchronization Performance Impact and Guidelines
The last chapter introduced synchronization operations and demonstrated their usage in some relatively simple examples. The next chapter provides more complex but realistic and useful examples and describes a general synchronization model that solves many practical problems and enhances program reliability. This short chapter is concerned with the impact that synchronization can have on application performance and techniques to minimize the impact.While thread synchronization is essential, there are some significant performance pitfalls, and we describe some of the major performance issues, both on single-processor and multiple-processor (SMP) systems. There are also trade-offs among alternative solutions. For example, CRITICAL_SECTIONs (CSs) and mutexes are nearly identical and solve the same fundamental problem. CSs are generally, but not always, the most efficient locking mechanism. CSs are also not as convenient to use as mutexes, as Chapter 10 demonstrates. In other cases, interlocked operations are sufficient, and it may even be possible to avoid synchronization altogether with careful design and implementation.CSmutex trade-offs are discussed first, along with SMP implications. CS spin counts, semaphore throttles, and processor affinity are other topics. The chapter ends with a set of performance guidelines.Note:
NT 5.0 made some significant performance improvements. Some of the issues identified here were much more severe with earlier NT versions and 9x.