liveness case on Lamport's bakery

Thread Starter

FreddoAvishi

Joined Mar 8, 2019
36
Hello Fellas ! , I'm trying to find if there would be a case of violation liveness on Lamport's bakery algorithm since I totally remove the row -13- on the algorithm's code.
there's ofcourse a violation of safety but I'm validating if there would be a case of violation of liveness case. ((thanks for helpers in advance))

here's the pseudo code of Lamport's bakery algorithm:

// declaration and initial values of global variables
1 Entering: array [1..NUM_THREADS] of bool = {false};
2 Number: array [1..NUM_THREADS] of integer = {0};
3
4 lock(integer i) {
5 Entering = true;
6 Number = 1 + max(Number[1], ..., Number[NUM_THREADS]);
7 Entering = false;
8 for (integer j = 1; j <= NUM_THREADS; j++) {
9 // Wait until thread j receives its number:
10 while (Entering[j]) { /* nothing */ }
11 // Wait until all threads with smaller numbers or with the same
12 // number, but with higher priority, finish their work:
13 while ((Number[j] != 0) && ((Number[j], j) < (Number, i))) { /* nothing */ } // -------e---------
14 }
15 }
16
17 unlock(integer i) {
18 Number = 0;
19 }
20
21 Thread(integer i) {
22 while (true) {
23 lock(i);
24 // The critical section goes here...
25 unlock(i);
26 // non-critical section...
27 }
28 }
 

Thread Starter

FreddoAvishi

Joined Mar 8, 2019
36
Update of correction **** I'm trying to find if there would be a case of violation liveness on Lamport's bakery algorithm since I remove from the row -13- the second statement ((Number[j], j) < (Number, i)) on the algorithm's code****
 

Thread Starter

FreddoAvishi

Joined Mar 8, 2019
36
Line 13 would be a 'yield' function on a single core system with non-preemptive cooperative multitasking. So, yes it would affect what Lamport calls a liveness property.

http://www.classiccmp.org/cini/pdf/HT68K/HT68K TCJ30p37.pdf

http://www.cs.cornell.edu/courses/cs2110/2013sp/L24-Concurrency Proofs/L24cs2110sp13.pdf
I've read what you gave me, but didn't find that if we remove row 13 then we may arrive to liveness, may you please have a case for that? I mean specific case, thanks alot
 

nsaspook

Joined Aug 27, 2009
13,312
http://lamport.azurewebsites.net/pubs/bakery.pdf

Liveness
here is each thread getting a 'fair' share of processing time so one or more threads don't get starved and execute in the proper turn. Lamport's bakery algorithm has limited utility in modern preemptive operating systems as the task scheduler with proper user program API calls assumes that function and there are out of order instructions branches in modern processors that require other measures (memory barriers) to insure Liveness.

https://www.geeksforgeeks.org/operating-system-bakery-algorithm/


 
Last edited:

Thread Starter

FreddoAvishi

Joined Mar 8, 2019
36
http://lamport.azurewebsites.net/pubs/bakery.pdf

Liveness
here is each thread getting a 'fair' share of processing time so one or more threads don't get starved and execute in the proper turn. Lamport's bakery algorithm has limited utility in modern preemptive operating systems as the task scheduler with proper user program API calls assumes that function and there are out of order instructions branches in modern processors that require other measures (memory barriers) to insure Liveness.

https://www.geeksforgeeks.org/operating-system-bakery-algorithm/


So if I understand you well; you mean if I remove totally the row of 13 (not specific statement in it) then I will get liveness as what you described .. Ye? Means thats all threads getting in without turn; so it's not fairness ..
 
Top