# What is bakery algorithm and how it solve the synchronization problem?

## What is bakery algorithm and how it solve the synchronization problem?

Bakery Algorithm is a critical section solution for N processes. The algorithm preserves the first come first serve property. Before entering its critical section, the process receives a number. Holder of the smallest number enters the critical section.

## What is bakery algorithm in operating system?

The Bakery algorithm is one of the simplest known solutions to the mutual exclusion problem for the general case of N process. The basic idea is that each non-thinking process has a variable that indicates the position of that process in a hypthetical queue of all the non-thinking processes.

## What is bakery mutual exclusion algorithm?

Lamport’s bakery algorithm is a computer algorithm devised by computer scientist Leslie Lamport, as part of his long study of the formal correctness of concurrent systems, which is intended to improve the safety in the usage of shared resources among multiple threads by means of mutual exclusion.

## Who has found the bakery algorithm?

Lamport. …which he called the “bakery algorithm,” involved assigning an integer to each process waiting to write to memory much the same way that a bakery patron obtains a number upon entering the store.

## What is the disadvantage of Lamport’s bakery algorithm?

Lamport’s Bakery Algorithm (Commun ACM 17:453–455, 1974) implements mutual exclusion for a fixed number of threads with the first-come first-served property. It has the disadvantage, however, that it uses integer communication variables that can become arbitrarily large.

## How is bakery algorithm used in process synchronization?

Bakery Algorithm is a critical section solution for N processes. The algorithm preserves the first come first serve property. Before entering its critical section, the process receives a number. Holder of the smallest number enters the critical section. if i < j Pi is served first; else Pj is served first.

## How is a timestamp used in Lamport’s algorithm?

Every site S i, keeps a queue to store critical section requests ordered by their timestamps. A timestamp is given to each critical section request using Lamport’s logical clock. Timestamp is used to determine priority of critical section requests. Smaller timestamp gets high priority over larger timestamp.

## How are critical sections executed in Lamport’s algorithm?

In Lamport’s Algorithm critical section requests are executed in the increasing order of timestamps i.e a request with smaller timestamp will be given permission to execute critical section first than a request with larger timestamp.