This chapter include objectives: To present the concept of process synchronization; to introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data; to present both software and hardware solutions of the critical-section problem; to examine several classical process-synchronization problems; to explore several tools that are used to solve process synchronization problems. | Chapter 5: Process Synchronization Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013 Chapter 5: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Mutex Locks Semaphores Classic Problems of Synchronization Monitors Synchronization Examples Alternative Approaches Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013 Objectives To present the concept of process synchronization. To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To present both software and hardware solutions of the critical-section problem To examine several classical process-synchronization problems To explore several tools that are used to solve process synchronization problems Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013 Background Processes can execute concurrently May be interrupted at any time, partially completing execution Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes Illustration of the problem: Suppose that we wanted to provide a solution to the consumer-producer problem that fills all the buffers. We can do so by having an integer counter that keeps track of the number of full buffers. Initially, counter is set to 0. It is incremented by the producer after it produces a new buffer and is decremented by the consumer after it consumes a buffer. Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne ©2013 Producer while (true) { /* produce an item in next produced */ while (counter == BUFFER_SIZE) ; /* do nothing */ buffer[in] = next_produced; in = (in + 1) % BUFFER_SIZE; counter++; } Operating System Concepts – 9th Edition Silberschatz, Galvin and Gagne .