Synchronization Examples
In Chapter 6, we presented the critical-section problem and focused on how race conditions can occur when multiple concurrent processes share data. We went on to examine several tools that address the critical-section problem by preventing race conditions from occurring. These tools ranged from low-level hardware solutions (such asmemory barriers and the compare-and-swap oper- ation) to increasingly higher-level tools (from mutex locks to semaphores to monitors). We also discussed various challenges in designing applications that are free from race conditions, including liveness hazards such as deadlocks. In this chapter, we apply the tools presented in Chapter 6 to several classic synchronization problems. We also explore the synchronization mechanisms used by the Linux, UNIX, and Windows operating systems, and we describe API details for both Java and POSIX systems.
CHAPTER OBJECTIVES
• Explain the bounded-buffer, readers–writers, and dining–philosophers synchronization problems.
• Describe specific tools used by Linux and Windows to solve process synchronization problems.
• Illustrate how POSIX and Java can be used to solve process synchroniza- tion problems.
• Design and develop solutions to process synchronization problems using POSIX and Java APIs.