Question: The Bakery Algorithm is an approach to providing mutually exclusive access to some resource for N processes where N >1. In essence it is supposed

The Bakery Algorithm is an approach to providing mutually exclusive access to some resource for N processes where N >1. In essence it is supposed to work the way a deli counter or bakery counter works. That is, each customer walks in, takes their number, and waits for their number to be called, at which point they access the resource (i.e. access their critical section). Each process executes the same code shown below. Unfortunately, this code has a major problem it contains race conditions. Fix the code by adding Binary Semaphores as needed to protect any variable(s) with race conditions wherever necessary. DO NOT protect code which does NOT not need to be protected that is wasteful.

Shared variables all N processes share the following wo integers

Global int counter = 1;

Global int next = 1;

-----------------------------------------------------

process X ( )

local int mynumber = next;

next = next + 1;

while ( counter != mynumber ) do

; // just wait for your turn

// access the resource here

counter = counter + 1;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!