際際滷

際際滷Share a Scribd company logo
Welcome
To
My Presentation
Presentation on
Bakery Algorithm
What is Bakery algorithm ?
 Bakery algorithm is an algorithm devised by computer scientist Leslie Lamport, which is intended
to improve the safety in the usage of shared resources among multiple threads by means of
mutual exclusion.
 In computer science, it is common for multiple threads to simultaneously access the same
resources. But data corruption can occur if two or more threads try to write into the same
memory location.
 Lamport's bakery algorithm is one of many mutual exclusion algorithms designed to prevent
concurrent threads entering critical sections of code concurrently to eliminate the risk of data
corruption.
How it works ?
 Before entering its critical section, the process receives a number. The smallest number enters the
critical section.
 If processes Pi and Pj receive the same number,
if Pi < Pj
Pi is served first;
else
Pj is served first.
Real life examples
P1 P2
In the above diagram there are two processes p1 and p2. the process p2 will go to the critical section because it has lowest
ticket number.
Token 9 Token 8
Real life examples
P1 P2
Here, we can see that there are two processes p1 and p2. The process p1 & p2 have same token number. Then process ID will be
checked. P1 process has lowest ID and will go to critical section first.
Token 9 Token 9
Conclusion
This algorithm model can be used to implement mutual exclusion on memory that lacks synchronization
primitives. It is remarkable that this algorithm is not built on top of some lower level "atomic" operation.
Lamport's bakery algorithm assumes a sequential consistency memory model. Few, if any, languages or
multi-core processors implement such a memory model. Therefore correct implementation of the algorithm
typically requires inserting fences to inhibit reordering.
Thank You!
3.CRITICAL SECTION :
Critical section is a code segment that accesses shared variables and has to be executed an atomic action.
Only one process can execute its critical section at a given time.
A mutual exclusion is a program object that prevents simultaneous access to a shared resource. This concept is used in concurrent
programming with a critical section, a piece of code in which processes or threads access a shared resource.
4. The Bakery algorithm is one of the simplest known solutions to the mutual exclusion problem for the general case of N process. Bakery
Algorithm is a critical section solution for N processes. The algorithm preserves the first come first serve property.
12. Bakery Algorithm (ID 9, p1) (ID 8, 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.
13. Bakery Algorithm (ID 8, p1) (ID 8, 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

More Related Content

What's hot (20)

Asymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptxAsymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptx
Rachit Jain
Fundamental of Algorithms
Fundamental of Algorithms Fundamental of Algorithms
Fundamental of Algorithms
Dr Shashikant Athawale
Critical Section Problem - Ramakrishna Reddy Bijjam
Critical Section Problem - Ramakrishna Reddy BijjamCritical Section Problem - Ramakrishna Reddy Bijjam
Critical Section Problem - Ramakrishna Reddy Bijjam
Ramakrishna Reddy Bijjam
01 Analysis of Algorithms: Introduction
01 Analysis of Algorithms: Introduction01 Analysis of Algorithms: Introduction
01 Analysis of Algorithms: Introduction
Andres Mendez-Vazquez
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
Abhimanyu Mishra
OS_Ch7
OS_Ch7OS_Ch7
OS_Ch7
Supriya Shrivastava
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms II
Mohamed Loey
All-Solution Satisfiability Modulo Theories: applications, algorithms and ben...
All-Solution Satisfiability Modulo Theories: applications, algorithms and ben...All-Solution Satisfiability Modulo Theories: applications, algorithms and ben...
All-Solution Satisfiability Modulo Theories: applications, algorithms and ben...
Quoc-Sang Phan
chapter 1
chapter 1chapter 1
chapter 1
yatheesha
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventions
saranyatdr
P3
P3P3
P3
lksoo
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
rajkumar1631010038
Mutual exclusion
Mutual exclusionMutual exclusion
Mutual exclusion
Dillip Behera
Algorithm analysis and efficiency
Algorithm analysis and efficiencyAlgorithm analysis and efficiency
Algorithm analysis and efficiency
ppts123456
Labsheet1 ec303 student
Labsheet1 ec303 studentLabsheet1 ec303 student
Labsheet1 ec303 student
farah146
Boothmultiplication
BoothmultiplicationBoothmultiplication
Boothmultiplication
melisha monteiro
J unit introduction
J unit introductionJ unit introduction
J unit introduction
Radim Pavlicek
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
Harshana Madusanka Jayamaha
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com
Asymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptxAsymptotic analysis of algorithms.pptx
Asymptotic analysis of algorithms.pptx
Rachit Jain
Critical Section Problem - Ramakrishna Reddy Bijjam
Critical Section Problem - Ramakrishna Reddy BijjamCritical Section Problem - Ramakrishna Reddy Bijjam
Critical Section Problem - Ramakrishna Reddy Bijjam
Ramakrishna Reddy Bijjam
01 Analysis of Algorithms: Introduction
01 Analysis of Algorithms: Introduction01 Analysis of Algorithms: Introduction
01 Analysis of Algorithms: Introduction
Andres Mendez-Vazquez
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
Algorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms IIAlgorithms Lecture 3: Analysis of Algorithms II
Algorithms Lecture 3: Analysis of Algorithms II
Mohamed Loey
All-Solution Satisfiability Modulo Theories: applications, algorithms and ben...
All-Solution Satisfiability Modulo Theories: applications, algorithms and ben...All-Solution Satisfiability Modulo Theories: applications, algorithms and ben...
All-Solution Satisfiability Modulo Theories: applications, algorithms and ben...
Quoc-Sang Phan
chapter 1
chapter 1chapter 1
chapter 1
yatheesha
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventions
saranyatdr
P3
P3P3
P3
lksoo
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
rajkumar1631010038
Algorithm analysis and efficiency
Algorithm analysis and efficiencyAlgorithm analysis and efficiency
Algorithm analysis and efficiency
ppts123456
Labsheet1 ec303 student
Labsheet1 ec303 studentLabsheet1 ec303 student
Labsheet1 ec303 student
farah146
J unit introduction
J unit introductionJ unit introduction
J unit introduction
Radim Pavlicek
Design & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture NotesDesign & Analysis of Algorithms Lecture Notes
Design & Analysis of Algorithms Lecture Notes
FellowBuddy.com

Similar to Presentation on Bakery Algorithm (20)

Debugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programsDebugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programs
PVS-Studio
design analysis of algorithmaa unit 1.pptx
design analysis of algorithmaa unit 1.pptxdesign analysis of algorithmaa unit 1.pptx
design analysis of algorithmaa unit 1.pptx
rajesshs31r
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
Sheba41
parellel computing
parellel computingparellel computing
parellel computing
katakdound
Arm developement
Arm developementArm developement
Arm developement
hirokiht
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdfADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
RGPV De Bunkers
Packer Genetics: The selfish code
Packer Genetics: The selfish codePacker Genetics: The selfish code
Packer Genetics: The selfish code
jduart
Algorithm - Introduction
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - Introduction
Madhu Bala
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlang
Mirko Bonadei
Clustering_Algorithm_DR
Clustering_Algorithm_DRClustering_Algorithm_DR
Clustering_Algorithm_DR
Nguyen Tran
Joe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsJoe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystems
Sentifi
Gk3611601162
Gk3611601162Gk3611601162
Gk3611601162
IJERA Editor
Railway Ticket Counter Problem With STM
Railway Ticket Counter Problem With STMRailway Ticket Counter Problem With STM
Railway Ticket Counter Problem With STM
IJERA Editor
Matopt
MatoptMatopt
Matopt
Afaf Soumia Medjden
maXbox Starter 45 Robotics
maXbox Starter 45 RoboticsmaXbox Starter 45 Robotics
maXbox Starter 45 Robotics
Max Kleiner
unit 2 hpc.pptx
unit 2 hpc.pptxunit 2 hpc.pptx
unit 2 hpc.pptx
gopal467344
Concurrency and parallel in .net
Concurrency and parallel in .netConcurrency and parallel in .net
Concurrency and parallel in .net
Mohammad Hossein Karami
ALGO.ppt
ALGO.pptALGO.ppt
ALGO.ppt
PidoonEsm
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
Sheba41
Control of Industrial Pneumatic & Hydraulic Systems using Serial Communicatio...
Control of Industrial Pneumatic & Hydraulic Systems using Serial Communicatio...Control of Industrial Pneumatic & Hydraulic Systems using Serial Communicatio...
Control of Industrial Pneumatic & Hydraulic Systems using Serial Communicatio...
IJSRD
Debugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programsDebugging and optimization of multi-thread OpenMP-programs
Debugging and optimization of multi-thread OpenMP-programs
PVS-Studio
design analysis of algorithmaa unit 1.pptx
design analysis of algorithmaa unit 1.pptxdesign analysis of algorithmaa unit 1.pptx
design analysis of algorithmaa unit 1.pptx
rajesshs31r
CP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithmsCP4151 Advanced data structures and algorithms
CP4151 Advanced data structures and algorithms
Sheba41
parellel computing
parellel computingparellel computing
parellel computing
katakdound
Arm developement
Arm developementArm developement
Arm developement
hirokiht
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdfADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
ADA Unit-1 Algorithmic Foundations Analysis, Design, and Efficiency.pdf
RGPV De Bunkers
Packer Genetics: The selfish code
Packer Genetics: The selfish codePacker Genetics: The selfish code
Packer Genetics: The selfish code
jduart
Algorithm - Introduction
Algorithm - IntroductionAlgorithm - Introduction
Algorithm - Introduction
Madhu Bala
An introduction to erlang
An introduction to erlangAn introduction to erlang
An introduction to erlang
Mirko Bonadei
Clustering_Algorithm_DR
Clustering_Algorithm_DRClustering_Algorithm_DR
Clustering_Algorithm_DR
Nguyen Tran
Joe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystemsJoe armstrong erlanga_languageforprogrammingreliablesystems
Joe armstrong erlanga_languageforprogrammingreliablesystems
Sentifi
Railway Ticket Counter Problem With STM
Railway Ticket Counter Problem With STMRailway Ticket Counter Problem With STM
Railway Ticket Counter Problem With STM
IJERA Editor
maXbox Starter 45 Robotics
maXbox Starter 45 RoboticsmaXbox Starter 45 Robotics
maXbox Starter 45 Robotics
Max Kleiner
unit 2 hpc.pptx
unit 2 hpc.pptxunit 2 hpc.pptx
unit 2 hpc.pptx
gopal467344
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
Sheba41
Control of Industrial Pneumatic & Hydraulic Systems using Serial Communicatio...
Control of Industrial Pneumatic & Hydraulic Systems using Serial Communicatio...Control of Industrial Pneumatic & Hydraulic Systems using Serial Communicatio...
Control of Industrial Pneumatic & Hydraulic Systems using Serial Communicatio...
IJSRD

Recently uploaded (20)

Water Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control Monthly - March 2025.pdfWater Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control
Multi objective genetic approach with Ranking
Multi objective genetic approach with RankingMulti objective genetic approach with Ranking
Multi objective genetic approach with Ranking
namisha18
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptxRAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
JenTeruel1
CS3451 INTRODUCTIONN TO OS unit ONE .pdf
CS3451 INTRODUCTIONN TO OS unit ONE .pdfCS3451 INTRODUCTIONN TO OS unit ONE .pdf
CS3451 INTRODUCTIONN TO OS unit ONE .pdf
PonniS7
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
ASHISHDESAI85
Air pollution is contamination of the indoor or outdoor environment by any ch...
Air pollution is contamination of the indoor or outdoor environment by any ch...Air pollution is contamination of the indoor or outdoor environment by any ch...
Air pollution is contamination of the indoor or outdoor environment by any ch...
dhanashree78
Unit II: Design of Static Equipment Foundations
Unit II: Design of Static Equipment FoundationsUnit II: Design of Static Equipment Foundations
Unit II: Design of Static Equipment Foundations
Sanjivani College of Engineering, Kopargaon
US Patented ReGenX Generator, ReGen-X Quatum Motor EV Regenerative Accelerati...
US Patented ReGenX Generator, ReGen-X Quatum Motor EV Regenerative Accelerati...US Patented ReGenX Generator, ReGen-X Quatum Motor EV Regenerative Accelerati...
US Patented ReGenX Generator, ReGen-X Quatum Motor EV Regenerative Accelerati...
Thane Heins NOBEL PRIZE WINNING ENERGY RESEARCHER
Lectureof nano 1588236675-biosensors (1).ppt
Lectureof nano 1588236675-biosensors (1).pptLectureof nano 1588236675-biosensors (1).ppt
Lectureof nano 1588236675-biosensors (1).ppt
SherifElGohary7
Industrial Valves, Instruments Products Profile
Industrial Valves, Instruments Products ProfileIndustrial Valves, Instruments Products Profile
Industrial Valves, Instruments Products Profile
zebcoeng
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptxGROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
meneememoo
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptxUNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
KesavanT10
Lessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the CloudLessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the Cloud
Igor Donchovski
autonomous vehicle project for engineering.pdf
autonomous vehicle project for engineering.pdfautonomous vehicle project for engineering.pdf
autonomous vehicle project for engineering.pdf
JyotiLohar6
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
NgocThang9
How to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using ArduinoHow to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using Arduino
CircuitDigest
Equipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding ProcessEquipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding Process
AhmadKamil87
04 MAINTENANCE OF CONCRETE PAVEMENTS.ppt
04  MAINTENANCE OF CONCRETE PAVEMENTS.ppt04  MAINTENANCE OF CONCRETE PAVEMENTS.ppt
04 MAINTENANCE OF CONCRETE PAVEMENTS.ppt
sreenath seenu
only history of java.pptx real bihind the name java
only history of java.pptx real bihind the name javaonly history of java.pptx real bihind the name java
only history of java.pptx real bihind the name java
mushtaqsaliq9
CS3451-OPERATING-SYSTEM NOTES ALL123.pdf
CS3451-OPERATING-SYSTEM NOTES ALL123.pdfCS3451-OPERATING-SYSTEM NOTES ALL123.pdf
CS3451-OPERATING-SYSTEM NOTES ALL123.pdf
PonniS7
Multi objective genetic approach with Ranking
Multi objective genetic approach with RankingMulti objective genetic approach with Ranking
Multi objective genetic approach with Ranking
namisha18
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptxRAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
RAMSES- EDITORIAL SAMPLE FOR DSSPC C.pptx
JenTeruel1
CS3451 INTRODUCTIONN TO OS unit ONE .pdf
CS3451 INTRODUCTIONN TO OS unit ONE .pdfCS3451 INTRODUCTIONN TO OS unit ONE .pdf
CS3451 INTRODUCTIONN TO OS unit ONE .pdf
PonniS7
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
Integration of Additive Manufacturing (AM) with IoT : A Smart Manufacturing A...
ASHISHDESAI85
Air pollution is contamination of the indoor or outdoor environment by any ch...
Air pollution is contamination of the indoor or outdoor environment by any ch...Air pollution is contamination of the indoor or outdoor environment by any ch...
Air pollution is contamination of the indoor or outdoor environment by any ch...
dhanashree78
Lectureof nano 1588236675-biosensors (1).ppt
Lectureof nano 1588236675-biosensors (1).pptLectureof nano 1588236675-biosensors (1).ppt
Lectureof nano 1588236675-biosensors (1).ppt
SherifElGohary7
Industrial Valves, Instruments Products Profile
Industrial Valves, Instruments Products ProfileIndustrial Valves, Instruments Products Profile
Industrial Valves, Instruments Products Profile
zebcoeng
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptxGROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
meneememoo
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptxUNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
KesavanT10
Lessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the CloudLessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the Cloud
Igor Donchovski
autonomous vehicle project for engineering.pdf
autonomous vehicle project for engineering.pdfautonomous vehicle project for engineering.pdf
autonomous vehicle project for engineering.pdf
JyotiLohar6
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
NgocThang9
How to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using ArduinoHow to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using Arduino
CircuitDigest
Equipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding ProcessEquipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding Process
AhmadKamil87
04 MAINTENANCE OF CONCRETE PAVEMENTS.ppt
04  MAINTENANCE OF CONCRETE PAVEMENTS.ppt04  MAINTENANCE OF CONCRETE PAVEMENTS.ppt
04 MAINTENANCE OF CONCRETE PAVEMENTS.ppt
sreenath seenu
only history of java.pptx real bihind the name java
only history of java.pptx real bihind the name javaonly history of java.pptx real bihind the name java
only history of java.pptx real bihind the name java
mushtaqsaliq9
CS3451-OPERATING-SYSTEM NOTES ALL123.pdf
CS3451-OPERATING-SYSTEM NOTES ALL123.pdfCS3451-OPERATING-SYSTEM NOTES ALL123.pdf
CS3451-OPERATING-SYSTEM NOTES ALL123.pdf
PonniS7

Presentation on Bakery Algorithm

  • 3. What is Bakery algorithm ? Bakery algorithm is an algorithm devised by computer scientist Leslie Lamport, which is intended to improve the safety in the usage of shared resources among multiple threads by means of mutual exclusion. In computer science, it is common for multiple threads to simultaneously access the same resources. But data corruption can occur if two or more threads try to write into the same memory location. Lamport's bakery algorithm is one of many mutual exclusion algorithms designed to prevent concurrent threads entering critical sections of code concurrently to eliminate the risk of data corruption.
  • 4. How it works ? Before entering its critical section, the process receives a number. The smallest number enters the critical section. If processes Pi and Pj receive the same number, if Pi < Pj Pi is served first; else Pj is served first.
  • 5. Real life examples P1 P2 In the above diagram there are two processes p1 and p2. the process p2 will go to the critical section because it has lowest ticket number. Token 9 Token 8
  • 6. Real life examples P1 P2 Here, we can see that there are two processes p1 and p2. The process p1 & p2 have same token number. Then process ID will be checked. P1 process has lowest ID and will go to critical section first. Token 9 Token 9
  • 7. Conclusion This algorithm model can be used to implement mutual exclusion on memory that lacks synchronization primitives. It is remarkable that this algorithm is not built on top of some lower level "atomic" operation. Lamport's bakery algorithm assumes a sequential consistency memory model. Few, if any, languages or multi-core processors implement such a memory model. Therefore correct implementation of the algorithm typically requires inserting fences to inhibit reordering.
  • 9. 3.CRITICAL SECTION : Critical section is a code segment that accesses shared variables and has to be executed an atomic action. Only one process can execute its critical section at a given time. A mutual exclusion is a program object that prevents simultaneous access to a shared resource. This concept is used in concurrent programming with a critical section, a piece of code in which processes or threads access a shared resource. 4. The Bakery algorithm is one of the simplest known solutions to the mutual exclusion problem for the general case of N process. Bakery Algorithm is a critical section solution for N processes. The algorithm preserves the first come first serve property. 12. Bakery Algorithm (ID 9, p1) (ID 8, 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. 13. Bakery Algorithm (ID 8, p1) (ID 8, 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