Chapter_6

Chapter_6 - Chapter 6: Process Synchronization s Background...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 6: Process Synchronization Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization Monitors Synchronization Examples
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Background Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes. Bounded buffer problem: There are N buffers Two types of processes, namely, Consumers and Producers have access to the N buffers. Producers produce items and place the items in the empty buffers. Consumers consume the items placed in the buffers Producers and consumers need to be synchronized to access the shared resource (buffers).
Background image of page 2
6.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts An Incorrect Solution to the Bounded- An Incorrect Solution to the Bounded- Buffer Problem Buffer Problem Shared data #define BUFFER_SIZE 10 typedef struct { . . . } item ; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; int counter = 0;
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6.4 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts An Incorrect Solution to … An Incorrect Solution to … Producer process item nextProduced; while (1) { while (counter == BUFFER_SIZE) ; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; counter++; }
Background image of page 4
6.5 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts An Incorrect Solution to … An Incorrect Solution to … Consumer process item nextConsumed; while (1) { while (counter == 0) ; /* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; counter--; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6.6 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts An Incorrect Solution to … An Incorrect Solution to … The statements counter++; counter--; must be performed atomically . Atomic operation means an operation that completes in its entirety without interruption.
Background image of page 6
6.7 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts An Incorrect Solution to … An Incorrect Solution to … The statement “ counter++ ” may be implemented in machine language as: register1 = counter register1 = register1 + 1 counter = register1 The statement “ counter-- ” may be implemented as: register2 = counter register2 = register2 – 1 counter = register2
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Silberschatz, Galvin and Gagne ©2005 Operating System Concepts An Incorrect Solution to … An Incorrect Solution to … If both the producer and consumer attempt to update the buffer concurrently, the assembly language statements may get interleaved.
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 12/14/2010.

Page1 / 49

Chapter_6 - Chapter 6: Process Synchronization s Background...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online