Module-3 Process Synchronization
Module-3 Process Synchronization
Process Synchronization
Introduction
Peterson’s solution
Synchronization hardware
Semaphores
A cooperating process is one that can affect or be affected by other processes executing in
the system.
Cooperating processes can either
– When one process in critical section, no other may be in its critical section
Critical section problem is to design protocol to solve this
General structure of process pi is
1. Mutual Exclusion
2. Progress
3. Bounded Waiting
do {
do {
flag[j] = TRUE;
flag[i] = TRUE;
turn = i;
turn = j;
while (flag[i] && turn == i);
while (flag[j] && turn == j);
critical section
critical section flag[j] = false;
flag[i] = false;
remainder section
remainder section } while (TRUE);
} while (TRUE);
false or turn == i. Also note that, if both processes can be executing in their critical
sections at the same time, then flag [0] ==flag [1] ==true.
These two observations imply that Po and P1 could not have successfully executed their
while statements at about the same time, since the value of turn can be either 0 or 1 but
cannot be both.
All modifications to the integer value of the semaphore in the wait () and signal()
operations must be executed indivisibly.
When one process modifies the semaphore value, no other process can simultaneously
modify that same semaphore value.
Must guarantee that no two processes can execute wait () and signal () on the same
Priority Inversion
Scheduling problem when lower-priority process holds a lock needed by higher-priority
process.
Solution: priority-inheritance protocol
‣ all processes that are accessing resources needed by a higher-priority process inherit the
higher priority until they are finished with the resources in question.
‣ When they are finished, their priorities revert to their original values.
1. Bounded-Buffer Problem
3. Dining-Philosophers Problem
do { do {
wait (full);
// produce an item in nextp wait (mutex);
// eat
signal ( chopstick[i] );
signal (chopstick[ (i + 1) % 5] );
// think
} While (true)
Although this solution guarantees that no two neighbors are eating simultaneously, it could still create a
deadlock.
Suppose that all five philosophers become hungry simultaneously and each grabs their left chopstick.