Process Synchronization
Process synchronization is the mechanism provided by the operating system to ensure that concurrent processes execute in a controlled and orderly manner when accessing shared resources. It is a fundamental requirement of any multiprogramming or multitasking system.
Real-world analogy: One ATM, two cards on the same account
Process A
local = 0 · next line: A: read counter → local
Process B
local = 0 · next line: B: read counter → local
Shared variable
0
expected final value: 2
Click “Run next line” alternately between A and B to create an interleaving.
- Mutual exclusion — at most one process inside the critical section.
- Progress — if no one is inside, a waiting process must be allowed in without unnecessary delay.
- Bounded waiting — a limit on how many times others can enter before a waiting process gets its turn (no starvation).
wait(S) { signal(S) {
while (S <= 0); S = S + 1;
S = S - 1; }
}
do {
wait(mutex); // entry section
critical section
signal(mutex); // exit section
remainder section
} while (true);Buffer is empty. Produce an item to begin.
1. A race condition occurs when:
2. wait(S) on a counting semaphore does what?
3. In the producer–consumer problem, the consumer blocks when:
Two processes each execute count++ 1000 times on a shared variable that starts at 0, with no synchronization. What is the minimum and maximum possible final value?