Page 108 - DCAP403_Operating System
P. 108
Unit 6: Process Synchronization
Sleep Notes
It is a system call that causes the caller to block, that is, be suspended until some other process
wakes it up.
Wakeup
It is a system call that wakes up the process.
Both ‘sleep’ and ‘wakeup’ system calls have one parameter that represents a memory address
used to match up ‘sleeps’ and ‘wakeups’.
Bounded Buffer Producers and Consumers
The bounded buffer producers and consumers assumes that there is a fixed buffer size i.e., a fi nite
numbers of slots are available.
Statement
To suspend the producers when the buffer is full, to suspend the consumers when the buffer is
empty, and to make sure that only one process at a time manipulates a buffer so there are no race
conditions or lost updates.
As an example how sleep-wakeup system calls are used, consider the producer-consumer
problem also known as bounded buffer problem.
Two processes share a common, fixed-size (bounded) buffer. The producer puts information into
the buffer and the consumer takes information out.
Trouble arises when:
1. The producer wants to put a new data in the buffer, but buffer is already full. Solution:
Producer goes to sleep and to be awakened when the consumer has removed data.
2. The consumer wants to remove data the buffer but buffer is already empty.
Solution: Consumer goes to sleep until the producer puts some data in buffer and wakes
consumer up.
Conclusion: This approaches also leads to same race conditions you have seen in earlier
approaches. Race condition can occur due to the fact that access to ‘count’ is unconstrained. The
essence of the problem is that a wakeup call, sent to a process that is not sleeping, is lost.
Task Discuss “sleep” and “Wakeup” stages.
6.3 Semaphores
E.W. Dijkstra (1965) abstracted the key notion of mutual exclusion in his concepts of
semaphores.
Defi nition
A semaphore is a protected variable whose value can be accessed and altered only by the
operations P and V and initialization operation called ‘Semaphoiinitislize’.
LOVELY PROFESSIONAL UNIVERSITY 101