Download presentation
Presentation is loading. Please wait.
Published byKatelynn Sutcliffe Modified over 9 years ago
1
Producer-Consumer One common situation: Producers and consumers communicate via a buffer.
2
Producer() { while (1) { >> P(empty); /* Get an empty buffer (decrease count), block if unavail */ P(mutex); /* acquire critical section: shared buffer */ >> V(mutex); /* release critical section */ V(full); /* increase number of full buffers */ } Producer
3
Consumer() { while (1) { P(full); P(mutex); <<< critical section: Remove item from shared buffer */ V(mutex); V(empty); } Consumer
4
Reader-Writer Problem Another common situation: Readers and writers must access a common data structure. Multiple readers are allowed, but only one writer. This solution allows readers to starve writers.
5
Writer() { while (1) { P(writing); >> V (writing); } Writer
6
Reader() { while (1) { P(mutex); rd_count++; if (1 == rd_count) P(writing); V(mutex); >> P(mutex) rd_count--; if ( 0 == rd_count) V(writing); V(mutex); } } Reader
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.