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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started