How and why to implement a critical section?
Why: to prevent race conditions.
- Two or more processes accessing the same memory loc AND
- At least one of the processes is writing to it.
Properties needed:
- Mutual Exclusion
- At most one process in CS
- To prove using contradiction: show impossible for $\geq 2$ processes in CS
- Progress
- If both processes are not in CS, then one of them can go into CS when it needs to.
- No starvation
- If one process is in CS and assuming it eventually leaves, the other processes can enter CS
Peterson’s algorithm
Lamport’s bakery algorithm