Back to Blog
Bakery story 2 algorithm7/20/2023 Reading the Wikipedia page (link above) may enlighten you further on the question as they describe the algorithm with different words than mine. One thread could call lock(), wait until it returns and check if it is still required to run the CS. This does not mean that a thread is forced to enter in the CS once the lock is acquired. Mutex.unlock() // mutex has to be released also in case of errorįor the way LBA is designed it does not allow a thread to "change idea" while waiting (there is no timeout notion in the algorithm): once a thread has called lock() it has to wait until lock() returns (possibly waiting all the other threads' unlock()). One typical way to use it is this (Java-like example): mutex.lock() title Toy Story 0 Jumanji 1 Grumpier Old Men 2 Waiting to Exhale 3 Father of the. Lamport's Bakery Algorithm (LBA) is just a deadlock-free algorithm that is used for mutual exclusion, so inside a bigger software. Of course, there could be an exception that the first restaurant opened. Anybody understand why they are there?ġ) The problem here is that you are missing the big picture. So the true and false Boolean seems useless to me. If a thread wants to enter it sets the Boolean value to true, but what is that Boolean value used for in the code? Because when a thread has been inside the critical area it changes its number to 0, so other threads in that way can see it's not interested in going inside the critical area, and if it decides it wants inside the critical area again, then it has to ask all the other threads what their number is and then add 1 to the maximum value which will be its number. In Lamport's bakery algorithm there is a Boolean value of "true" or "false". If a thread wants to get into the critical area it picks a number, but what if it changes its mind while it's waiting in line? does it then change its number to 0 or does it go through the critical area anyway when it is its turn? Tons of bakery themes including modern. Thousands of decoration options offer styles for everyone. First when it picks a number higher than 0 it is interested going inside the critical area. DECORATE your bakery with thousands of unique tables, wallpapers, art pieces and more - If you can dream it, you can design it in Bakery Story 2 Use tables, chairs, paintings, plants and much more to give your bakery that personal touch. When a thread exits the critical area then it put it's number to 0, meaning it's not interested in going inside the critical area. The thread with the lowest number can enter the critical zone and if two or more threads have the lowest number then the thread with the lowest process id will be allowed to enter the critical area. The thing I do understand is that each thread ask all other threads what number they have.Then the thread takes the maximum number and add 1 to that and give that number to itself. I have problems understanding Lamport's bakery algorithm.
0 Comments
Read More
Leave a Reply. |