Bakery Algorithm
Bakery Algorithm
Bakery Algorithm
University of UAJ&K
neelum campus
Introduction to
Bakery Algorithm
By:
Mehdi Hussain # 36
Khizar Hayyat # 25
Anees Mehdi # 35
Supervisor :
Prof. Sir.Saqib.Khushhal.
Spring 2017
Class presentation for the course: “ Operating System”
All the materials are copy rights of their respective authors as listed in references.
Contants:
Critical Section
Hardware Requirements for Bakery Algorithm
Software Requirements for Bakery Algorithm
Introduction to Bakery Algorithm
Bakery Algorithm Notations
Bakery Algorithm Data Structure
2
CRITICAL SECTION :
3
CRITICAL SECTION Example :
Do
{
Entry section
Critical section
Exit section
Remainder-section
}
While (true)
4
CRITICAL SECTION Solutions Criteria:
1.mutual exclusion:
Only one process should
execute in its critical section.
2.progress:
If no process is executing in its
critical section and some process wish to
enter the critical section. Then only those
processes that are not executing in its
remainder section can participate.
5
CRITICAL SECTION Solutions Criteria:
3.Bounded waiting:
There is a limit on the
number of times that other process are
allowed to enter their critical section.
6
Hardware Requirements for Bakery Algorithm
7
Software Requirements for Bakery Algorithm
8
Introduction to Bakery Algorithm:
10
Bakery Algorithm
11
Bakery Algorithm
(Ticket # 25, p1) (Ticket # 24, p2)
in the above diagram we can see that there are two processes p1 and
p2.the process p2 will go to the critical section because it has lowest ticket
number.
12
Bakery Algorithm
(Ticket # 24, p1) (Ticket # 24, p2)
In the above diagram we can see that there are two processes p1 and
p2.the process p1 & p2 have same ticket number .Then process ID will be
checked. P1 process has lowest ID and will go to critical section first
13
Bakery Algorithm
Data Structures
boolean choosing[n];
int number[n];
These data structures are initialized
to false and 0, respectively
14
Bakery Algorithm
Structure of Pi
do {
choosing[i] = true;
number[i] = max(number[0],
number[1], …,
number [n – 1]) + 1;
choosing[i] = false;
15
Bakery Algorithm
Critical Section
16
Bakery Algorithm
number[i] = 0;
www.cisco.com
remainder section
} while (1);
17
Bakery Algorithm
Process Number
P0 3
P1 0
P2 7
P3 4
P4 8
18
Bakery Algorithm
P0 P2 P3 P4
(3,0) < (3,0) (3,0) < (7,2) (3,0) < (4,3) (3,0) < (8,4)
(7,2) < (3,0) (7,2) < (7,2) (7,2) < (4,3) (7,2) < (8,4)
(4,3) < (3,0) (4,3) < (7,2) (4,3) < (4,3) (4,3) < (8,4)
(8,4) < (3,0) (8,4) < (7,2) (8,4) < (4,3) (8,4) < (8,4)
19
Bakery Algorithm
20
21