CS 3733 Operating Systems
Lecture 33 [4/6/98]: Classical Synchronization Problems
Read Section 6.5
Three classical problems in synchronization
- Bounded buffer problem
- Assume a pool of n buffers each of which can contain one item.
- Use three semaphores:
mutex
, empty
and full
.
- The
mutex
semaphore is initialized to 1.
- The
empty
and full
semaphores count the number of empty and full buffers.
They are initialized to n and 0.
- Producer-consumer (unbounded)
- Reader-writer problem (4 variations)
Consider a shared file in which some processes need to only read, but others
may need to update (read and write).
- Strong reader preference
No reader will be kept waiting unless a writer has already obtained
permission to write.
That is, no reader will be kept waiting because a writer is waiting.
This problem may have starvation of writers.
- Strong writer preference - this one is harder
Once a writer is waiting, it gets to write as soon as possible.
That is, new readers must wait if a writer is waiting.
This problem may have starvation of readers.
- Weak reader preference - Readers can continue to get
in as long as a reader is reading, but when no one is accessing,
the next access is selected on a FIFO basis.
- Weak writer preference - Readers can continue to
get until a writer is next in line.
Real implementation of semaphores
Skill: Understand the classical synchronization problems.
Revised 4/6/98