3. Introduction
This algorithm solves the critical section problem for n processes in software. The basic idea is
that of a bakery customers take numbers, and whoever has the lowest number gets service
next. Here, of course, "service" means entry to the critical section.
4. Background
In computer science, it is common for multiple threads to simultaneously access the same
resources. 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.
5. Working Principle
Before entering its critical section, the process receives a number. Holder of the smallest
number enters the critical section.
If processes Pi and Pj receive the same number
if i < j
Pi is served first;
else
Pj is served first.
The numbering scheme always generates numbers in increasing order of enumeration; i.e.,
1, 2, 3, 3, 3, 3, 4, 5................