Module 6 - Process synchronization. Chapter 6 is concerned with the topic of process synchronization among concurrently executing processes. Concurrency is generally very hard for students to deal with correctly, and so we have tried to introduce it and its problems with the classic process coordination problems: mutual exclusion, bounded-buffer, readers/writers, and so on. An understanding of these problems and their solutions is part of current operating system theory and development. | Lecture Operating system concepts Fifth edition Module 6 - Avi Silberschatz Peter Galvin Module 6 Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris 2 Atomic Transactions Silberschatz and Galvin 1999 Background Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes. Shared-memory solution to bounded-butter problem Chapter 4 allows at most n 1 items in buffer at the same time. A solution where all N buffers are used is not simple. Suppose that we modify the producer-consumer code by adding a variable counter initialized to 0 and incremented each time a new item is added to the buffer Silberschatz and Galvin 1999 Bounded-Buffer Shared data type item var buffer array of item in out counter in out counter 0 Producer process repeat produce an item in nextp while counter n do no-op buffer in nextp in in 1 mod n counter counter 1 until false Silberschatz and Galvin 1999 Bounded-Buffer Cont. Consumer process repeat while counter 0 do no-op nextc buffer out out out 1 mod n counter counter 1 consume the item in nextc until false The statements counter counter 1 counter counter - 1 must be executed atomically. Silberschatz and Galvin 1999 The Critical-Section Problem n processes all competing to use some shared data Each process has a code segment called critical section in which the shared data is accessed. Problem ensure that when one process is executing in its critical section no other process is allowed to execute in its critical section. Structure of process Pi repeat entry section critical section exit section reminder section until false Silberschatz and Galvin 1999 Solution to Critical-Section Problem 1. Mutual Exclusion. If process Pi is executing in its critical section then