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 }
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 }