SlideShare a Scribd company logo
2
Most read
4
Most read
5
Most read
6.1 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
n Process Critical Section Problem
 Consider a system of n processes (P0, P1 ... Pn-1).
 Each process has a segment of code called a
critical section in which the process may change
shared data.
 When one process is executing its critical section,
no other process is allowed to execute in its critical
section.
 The critical section problem is to design a protocol
to serialize executions of critical sections.
6.2 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
Bakery Algorithm
 By Leslie Lamport
 Before entering its critical section, process
receives a ticket number. Holder of the smallest
ticket number enters the critical section.
 If processes Pi and Pj receive the same number,
then if i < j, then Pi is served first; else Pj is served
first.
 The ticket numbering scheme always generates
numbers in the increasing order of enumeration;
i.e., 1, 2, 3, 4, 5 ...
6.3 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
Bakery Algorithm
Notations
 (ticket #, process id #)
(a,b) < (c,d) if a < c or
if a == c and b < d
 max (a0,…, an-1) is a number, k, such
that k ≥ ai for i = 0, …, n–1
6.4 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
Bakery Algorithm
Data Structures
 boolean choosing[n];
 int number[n];
These data structures are initialized to false and 0,
respectively
6.5 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
Bakery Algorithm
 Structure of Pi
do {
choosing[i] = true;
number[i] = max(number[0],number[1],…,number [n – 1]) + 1;
choosing[i] = false;
for (j = 0; j < n; j++) {
while (choosing[j]) ;
while ( (number[j] != 0) && ((number[j], j) < (number[i], i)) ) ;
}
Critical Section
number[i] = 0;
Remainder section
} while (1);
6.6 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
Bakery Algorithm
Process Number
P0 3
P1 0
P2 7
P3 4
P4 8
P0 P2 P3 P4
(3,0) < (3,0) (3,0) < (7,2) (3,0) < (4,3) (3,0) < (8,4)
Number[1] = 0 Number[1] = 0 Number[1] = 0 Number[1] = 0
(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)
1 3 2 4
6.7 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
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
 P2 gets into its CS and P4 waits for it to get out
 P4 gets into its CS
 Sequence of execution of processes:
<P0, P3, P2, P4>
6.8 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
Bakery Algorithm
 Meets all three requirements:
 Mutual Exclusion:
(number[j], j) < (number[i], i) cannot be true for both Pi and Pj
 Progress:
 Decision takes complete execution of the ‘for loop’ by one
process
 No process in its ‘Remainder Section’ (with its number set to
0) participates in the decision making
 Bounded-waiting:
At most one entry by each process (n-1 processes) and then
a requesting process enters its critical section (First-Come-
First-Serve)
6.9 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
Synchronization Hardware
Many systems provide hardware support for critical section code
Uniprocessors – could disable interrupts
Currently running code would execute without preemption
Generally too inefficient on multiprocessor systems
Modern machines provide special atomic hardware instructions
 Atomic = non-interruptable
Either test memory word and set value
Or swap contents of two memory words
6.9 Silberschatz, Galvin and GagneOperating System Concepts – 8th
Edition
Synchronization Hardware
Many systems provide hardware support for critical section code
Uniprocessors – could disable interrupts
Currently running code would execute without preemption
Generally too inefficient on multiprocessor systems
Modern machines provide special atomic hardware instructions
 Atomic = non-interruptable
Either test memory word and set value
Or swap contents of two memory words

More Related Content

PPT
Unit 5 usability and satisfaction test
PPTX
Semophores and it's types
PPTX
Thread scheduling in Operating Systems
PDF
2D Transformation in Computer Graphics
PPTX
Design of a two pass assembler
PPT
Real-Time Scheduling
PPTX
Theory of Computation - Strings and Languages and Proofs (Lecture 2)
PDF
Rayleigh model
Unit 5 usability and satisfaction test
Semophores and it's types
Thread scheduling in Operating Systems
2D Transformation in Computer Graphics
Design of a two pass assembler
Real-Time Scheduling
Theory of Computation - Strings and Languages and Proofs (Lecture 2)
Rayleigh model

What's hot (20)

PPTX
Computer Graphics - Hidden Line Removal Algorithm
PPTX
A Role of Lexical Analyzer
PPTX
DAA ppt.pptx
PPTX
Swapping | Computer Science
PPTX
Hidden surface removal
PPTX
I/O devices - Computer graphics
PPTX
Critical Section in Operating System
PPTX
3D Transformation
PDF
Notes 2D-Transformation Unit 2 Computer graphics
PPT
Peterson Critical Section Problem Solution
PDF
Ch8 (1) morris mano
PPTX
Cs419 lec10 left recursion and left factoring
PPTX
LINEAR BOUNDED AUTOMATA (LBA).pptx
PPTX
Threads and multi threading
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
PPT
Dinive conquer algorithm
PPTX
Process management in operating system | process states | PCB | FORK() | Zomb...
PDF
10.Design Of Two Pass Assembler in system software.pdf
PPTX
Compiler: Syntax Analysis
Computer Graphics - Hidden Line Removal Algorithm
A Role of Lexical Analyzer
DAA ppt.pptx
Swapping | Computer Science
Hidden surface removal
I/O devices - Computer graphics
Critical Section in Operating System
3D Transformation
Notes 2D-Transformation Unit 2 Computer graphics
Peterson Critical Section Problem Solution
Ch8 (1) morris mano
Cs419 lec10 left recursion and left factoring
LINEAR BOUNDED AUTOMATA (LBA).pptx
Threads and multi threading
Type Checking(Compiler Design) #ShareThisIfYouLike
Dinive conquer algorithm
Process management in operating system | process states | PCB | FORK() | Zomb...
10.Design Of Two Pass Assembler in system software.pdf
Compiler: Syntax Analysis
Ad

Viewers also liked (18)

PPTX
Performance of spread spectrum system
PDF
Dining philosopher mutex_2
PPTX
Producer Consumer
PPTX
Spread Spectrum System
PPT
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
PPTX
Producer and consumer classical problem
PPTX
Mutual Exclusion using Peterson's Algorithm
PPTX
Producer Consumer Problem
PPT
PDF
Dining Philosopher's Problem
PPTX
Operating system critical section
PPTX
Producer consumer
PPT
Process Synchronization
PPTX
Spread spectrum
PPTX
Project of mini bakery
PDF
8. mutual exclusion in Distributed Operating Systems
DOC
Synopsis on billing system
Performance of spread spectrum system
Dining philosopher mutex_2
Producer Consumer
Spread Spectrum System
Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems
Producer and consumer classical problem
Mutual Exclusion using Peterson's Algorithm
Producer Consumer Problem
Dining Philosopher's Problem
Operating system critical section
Producer consumer
Process Synchronization
Spread spectrum
Project of mini bakery
8. mutual exclusion in Distributed Operating Systems
Synopsis on billing system
Ad

Similar to Bakery algorithm (20)

PPT
Ch7 OS
 
PPTX
15- Bakery-Algorithm.pptx
PPT
Chapter 6
PDF
Module-3-Operating system process-COE.pdf
PPT
PPTX
process synchronisation operating system
PPT
Process synchonization : operating system ( Btech cse )
PPT
Operating System memory management CH6-OS (2).PPT
PPT
Operating Systems Chapter-6 power PointT
PPT
Chapter 5-Process Synchronization 22.ppt
PDF
Process synchronisation. Chapter .......
PPTX
chapter4.pptx
PPT
ch6.ppt
PPTX
chapterrrrrrrrrrrrrrrrr...r.r.r.r.6.pptx
PPTX
Operating Systems Chapter 6 silberschatz
PPTX
chapter 6 of computer operating system and fundamentals
PPT
Galvin-operating System(Ch7)
PDF
ch6_EN_BK_syn1.pdf
PPT
U3-PPT-1 (1).ppt
Ch7 OS
 
15- Bakery-Algorithm.pptx
Chapter 6
Module-3-Operating system process-COE.pdf
process synchronisation operating system
Process synchonization : operating system ( Btech cse )
Operating System memory management CH6-OS (2).PPT
Operating Systems Chapter-6 power PointT
Chapter 5-Process Synchronization 22.ppt
Process synchronisation. Chapter .......
chapter4.pptx
ch6.ppt
chapterrrrrrrrrrrrrrrrr...r.r.r.r.6.pptx
Operating Systems Chapter 6 silberschatz
chapter 6 of computer operating system and fundamentals
Galvin-operating System(Ch7)
ch6_EN_BK_syn1.pdf
U3-PPT-1 (1).ppt

More from Um e Farwa (11)

PDF
HCI LAB MANUAL
PDF
HCI LAB MANUAL
PPTX
Tele presence and co-presence in HCI
PPTX
Cognitive frameworks in HCI
PDF
Virtual reality v/s augmented reality
PDF
Cognition in HCI
PPTX
IINTERFACE METAPHORES , INTERACTION TYPES AND INTERACTION PARADIGMS IN HCI
PDF
Understanding the Problem Space and Conceptualizing in HCI
PPTX
14 technologies every web developer should be able to understand
PPTX
Why we need functions in c
PPTX
Good and Poor design HCI perceptive
HCI LAB MANUAL
HCI LAB MANUAL
Tele presence and co-presence in HCI
Cognitive frameworks in HCI
Virtual reality v/s augmented reality
Cognition in HCI
IINTERFACE METAPHORES , INTERACTION TYPES AND INTERACTION PARADIGMS IN HCI
Understanding the Problem Space and Conceptualizing in HCI
14 technologies every web developer should be able to understand
Why we need functions in c
Good and Poor design HCI perceptive

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Cloud computing and distributed systems.
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
cuic standard and advanced reporting.pdf
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
20250228 LYD VKU AI Blended-Learning.pptx
sap open course for s4hana steps from ECC to s4
Cloud computing and distributed systems.
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding
Understanding_Digital_Forensics_Presentation.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Programs and apps: productivity, graphics, security and other tools
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf

Bakery algorithm

  • 1. 6.1 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition n Process Critical Section Problem  Consider a system of n processes (P0, P1 ... Pn-1).  Each process has a segment of code called a critical section in which the process may change shared data.  When one process is executing its critical section, no other process is allowed to execute in its critical section.  The critical section problem is to design a protocol to serialize executions of critical sections.
  • 2. 6.2 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition Bakery Algorithm  By Leslie Lamport  Before entering its critical section, process receives a ticket number. Holder of the smallest ticket number enters the critical section.  If processes Pi and Pj receive the same number, then if i < j, then Pi is served first; else Pj is served first.  The ticket numbering scheme always generates numbers in the increasing order of enumeration; i.e., 1, 2, 3, 4, 5 ...
  • 3. 6.3 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition Bakery Algorithm Notations  (ticket #, process id #) (a,b) < (c,d) if a < c or if a == c and b < d  max (a0,…, an-1) is a number, k, such that k ≥ ai for i = 0, …, n–1
  • 4. 6.4 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition Bakery Algorithm Data Structures  boolean choosing[n];  int number[n]; These data structures are initialized to false and 0, respectively
  • 5. 6.5 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition Bakery Algorithm  Structure of Pi do { choosing[i] = true; number[i] = max(number[0],number[1],…,number [n – 1]) + 1; choosing[i] = false; for (j = 0; j < n; j++) { while (choosing[j]) ; while ( (number[j] != 0) && ((number[j], j) < (number[i], i)) ) ; } Critical Section number[i] = 0; Remainder section } while (1);
  • 6. 6.6 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition Bakery Algorithm Process Number P0 3 P1 0 P2 7 P3 4 P4 8 P0 P2 P3 P4 (3,0) < (3,0) (3,0) < (7,2) (3,0) < (4,3) (3,0) < (8,4) Number[1] = 0 Number[1] = 0 Number[1] = 0 Number[1] = 0 (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) 1 3 2 4
  • 7. 6.7 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition 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  P2 gets into its CS and P4 waits for it to get out  P4 gets into its CS  Sequence of execution of processes: <P0, P3, P2, P4>
  • 8. 6.8 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition Bakery Algorithm  Meets all three requirements:  Mutual Exclusion: (number[j], j) < (number[i], i) cannot be true for both Pi and Pj  Progress:  Decision takes complete execution of the ‘for loop’ by one process  No process in its ‘Remainder Section’ (with its number set to 0) participates in the decision making  Bounded-waiting: At most one entry by each process (n-1 processes) and then a requesting process enters its critical section (First-Come- First-Serve)
  • 9. 6.9 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition Synchronization Hardware Many systems provide hardware support for critical section code Uniprocessors – could disable interrupts Currently running code would execute without preemption Generally too inefficient on multiprocessor systems Modern machines provide special atomic hardware instructions  Atomic = non-interruptable Either test memory word and set value Or swap contents of two memory words
  • 10. 6.9 Silberschatz, Galvin and GagneOperating System Concepts – 8th Edition Synchronization Hardware Many systems provide hardware support for critical section code Uniprocessors – could disable interrupts Currently running code would execute without preemption Generally too inefficient on multiprocessor systems Modern machines provide special atomic hardware instructions  Atomic = non-interruptable Either test memory word and set value Or swap contents of two memory words