Lecture Operating systems: Lesson 21 - Dr. Syed Mansoor Sarwar. The main topics covered in this lesson include: 2-process critical section problem solution, N-process critical section problem, the bakery algorithm, hardware solutions, synchronization hardware, solutions based on the TSL and swap instructions, . | Operating Systems Lecture 21 Syed Mansoor Sarwar Agenda for Today Review of previous lecture 2-Process CS problem solution N-Process CS problem The Bakery Algorithm Hardware solutions Recap of lecture 28 April 2022 Copyright Virtual University of Pakistan Review of Lecture 20 2-Process Critical Section Problem Solution n-Process Critical Section Problem The Bakery Algorithm 28 April 2022 Copyright Virtual University of Pakistan Bakery Algorithm Structure of Pi do choosing i true number i max number 0 number 1 number n 1 1 choosing i false 28 April 2022 Copyright Virtual University of Pakistan Bakery Algorithm for j 0 j lt n j while choosing j while number j 0 amp amp number j j lt number i i Critical Section 28 April 2022 Copyright Virtual University of Pakistan Bakery Algorithm number i 0 remainder section while 1 28 April 2022 Copyright Virtual University of Pakistan Bakery Algorithm Process Number P0 3 P1 0 P2 7 P3 4 P4 8 28 April 2022 Copyright Virtual University of Pakistan Bakery Algorithm P0 P2 P3 P4 3 0 lt 3 0 3 0 lt 7 2 3 0 lt 4 3 3 0 lt 8 4 Number 1 0 Number 1 0 Number 1 0 Number 1 0 7 2 lt 3 0 7 2 lt 7 2 7 2 lt 4 3 7 2 lt 8 4 4 3 lt 3 0 4 3 lt 7 2 4 3 lt 4 3 4 3 lt 8 4 8 4 lt 3 0 8 4 lt 7 2 8 4 lt 4 3 8 4 lt 8 4 28 April 2022 Copyright Virtual University of 1 3 Pakistan 2 4 Bakery Algorithm P1 not interested to get into its critical section number 1 is 0 P2 P3 and P4 wait for P0 P0 gets into its CS get out and sets its number to 0 P3 get into its CS and P2 and P4 wait for it to get out of its CS 28 April 2022 Copyright Virtual University of Pakistan Bakery Algorithm P2 gets into its CS and P4 waits for it to get out P4 gets into its CS Sequence of execution of processes 28 April 2022 Copyright Virtual University of Pakistan Bakery Algorithm Meets all three requirements Mutual Exclusion number j j lt number i i cannot be true for both Pi and Pj Bounded-waiting At most one entry by each process n-1 processes and then a requesting process enters its .