tailieunhanh - Lecture Operating system concepts (Fifth edition): Module 6 - Avi Silberschatz, Peter Galvin

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. | 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 Operating System Concepts 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 Operating System Concepts Bounded-Buffer Shared data type item = ; var buffer array [0n-1] of item; in, out: 0n-1; counter: 0n; in, out, counter := 0; Producer process repeat produce an item in nextp while counter = n do . | 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 Operating System Concepts 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 Operating System Concepts Bounded-Buffer Shared data type item = ; var buffer array [0n-1] of item; in, out: 0n-1; counter: 0n; 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; Operating System Concepts 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. Operating System Concepts 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; Operating System Concepts Solution to Critical-Section Problem 1. Mutual Exclusion. If process Pi is executing in its critical section, then no other processes can .