Please note that the content of this book primarily consists of articles
available from Wikipedia or other free sources online. Lamport's bakery
algorithm is a computer 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. Data corruption can occur if two or more
threads try to write into the same memory location, or if one thread
reads a memory location before another has finished writing into it.
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.