The psuedocode of Lamport’s bakery algorithm is given below….

The psuedocode of Lamport’s bakery algorithm is given below. Fully explain why the “choosing” phase is necessary. boolean[n] choosing;int[n] ticket;startThreads();Txvoid main() { int x = threadNumber; while (!done) { choosing[x] = true; ticket[x] = maxValue(ticket) + 1; choosing[x] = false; for (int i = 0; i < n; i++) { if (i == x) continue; while (choosing[i] == true) ; while (ticket[i] != 0 && ticket[i] < ticket[x]) ; if (ticket[i] == ticket[x] && i < x) while (ticket[i] != 0 && ticket[i] == ticket[x]) ; } /* CRITICAL SECTION GOES HERE */ ticket[x] = 0; /* non-critical code */ }}

Below is the correct pseudocode of the ‘atomic swap’ mutual…

Below is the correct pseudocode of the ‘atomic swap’ mutual exclusion solution. Is indefinite postponement possible here? Explain why or why not. boolean occupied = false;startThreads();T1 T2void main() { void main() { boolean t1MustWait = true; boolean t2MustWait = true; while (!done) { while (!done) { do { do { swap(t1MustWait, occupied); swap(t2MustWait, occupied); } while (t1MustWait); } while (t2MustWait); // critical section // critical section t1MustWait = true; t2MustWait = true; occupied = false; occupied = false; // non-critical section // non-critical section } }} } The code is reproduced below with T2’s codebelow T1’s in case it is easier to read that way: T1void main() { boolean t1MustWait = true; while (!done) { do { swap(t1MustWait, occupied); } while (t1MustWait); // critical section t1MustWait = true; occupied = false; // non-critical section }}T2void main() { boolean t2MustWait = true; while (!done) { do { swap(t2MustWait, occupied); } while (t2MustWait); // critical section t2MustWait = true; occupied = false; // non-critical section }}