tailieunhanh - Lecture Operating system concepts (Sixth ed) - Chapter 7: Process synchronization

A cooperating process is one that can affect or be affected by other processes executing in the system. Cooperating processes can either directly share a logical address space (that is, both code and data) or be allowed to share data only through files or messages. The former case is achieved through the use of threads, discussed in chapter 4. Concurrent access to shared data may result in data inconsistency, however. In this chapter, we discuss various mechanisms to ensure the orderly execution of cooperating processes that share a logical address space, so that data consistency is maintained. | Chapter 7 Process Synchronization Background The Critical-Section Problem Synchronization Hardware Semaphores Classical Problems of Synchronization Critical Regions Monitors Synchronization in Solaris 2 Windows 2000 Operating System Concepts Silberschatz Galvin and Gagne 2002 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 Silberschatz Galvin and Gagne 2002 Bounded-Buffer Shared data define BUFFER_SIZE 10 typedef struct . item Item buffer BUFFER_SIZE int in 0 int out 0 int counter 0 Operating System Concepts Silberschatz Galvin and Gagne 2002 Bounded-Buffer Producer process item nextProduced while 1 while counter BUFFER_SIZE do nothing buffer in nextProduced in in 1 BUFFER_SIZE counter Operating System Concepts Silberschatz Galvin and Gagne 2002 Bounded-Buffer Consumer process item nextConsumed while 1 while counter 0 do nothing nextConsumed buffer out out out 1 BUFFER_SIZE counter-- Operating System Concepts Silberschatz Galvin and Gagne 2002