ch06 - Chapter 6: Process Synchronization Chapter Module 6:...

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

View Full Document Right Arrow Icon
Chapter 6: Process Synchronization Chapter 6: Process Synchronization
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 Module 6: Process Synchronization Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems of Synchronization Monitors Synchronization Examples Atomic Transactions
Background image of page 2
6.3 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Producer-Consumer Problem Producer-Consumer Problem Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process unbounded-buffer places no practical limit on the size of the buffer bounded-buffer assumes that there is a fixed buffer size
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 Bounded-Buffer – Shared-Memory Solution Bounded-Buffer – Shared-Memory Solution Shared data #define BUFFER_SIZE 10 Typedef struct { . . . } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0;
Background image of page 4
6.5 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Bounded-Buffer – Insert() Method Bounded-Buffer – Insert() Method //Producer while (true) { /* Produce an item */ while (((in = (in + 1) % BUFFER SIZE count) == out) ; /* do nothing -- no free buffers */ buffer[in] = item; in = (in + 1) % BUFFER SIZE; }
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 Bounded Buffer – Remove() Method Bounded Buffer – Remove() Method //Consumer while (true) { while (in == out) ; // do nothing -- nothing to consume // remove an item from the buffer item = buffer[out]; out = (out + 1) % BUFFER SIZE; return item; }
Background image of page 6
6.7 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Bounded Buffer Bounded Buffer Problem in previous example? Solution is correct, but can only use BUFFER_SIZE-1 elements, by assuming one producer and one consumer
Background image of page 7

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

View Full DocumentRight Arrow Icon
6.8 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 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 count that keeps track of the number of full buffers. Initially, count 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.
Background image of page 8
6.9 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Producer Producer while (true) /* produce an item and put in nextProduced while (count == BUFFER_SIZE); // do nothing buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; }
Background image of page 9

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

View Full DocumentRight Arrow Icon
6.10 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Consumer Consumer while (1) { while (count == 0); // do nothing nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; /* consume the item in nextConsumed }
Background image of page 10
6.11
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2011 for the course CSSE 250 taught by Professor Dr.yingwuzhu during the Spring '11 term at UH Clear Lake.

Page1 / 59

ch06 - Chapter 6: Process Synchronization Chapter Module 6:...

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

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