Is the following pseudocode correct or incorrect? If it is c…

Is the following pseudocode correct or incorrect? If it is correct, explain how it correctly enforces mutual exclusion. If it is incorrect, explain why. while (!exit) { /* LENGTHY EVENT PROCESSING CODE GOES HERE */ int currEvents = totalEvents; enterMutualExclusion(); // Assume this works { totalEvents = currEvents + 1; } exitMutualExclusion(); // Assume this works}

Below is the pseudocode of the first two versions of Dekker’…

Below is the pseudocode of the first two versions of Dekker’s algorithm. Explain the problem with the first that is corrected by the second and how the second corrects this problem. Note: The code of the threads (after the first global lines) will be written TWICE for each version. The first time, the code of the two threads are side-by-side to make it easier to compare them. But in case this does not show up properly on your screen, the code will be written again with T2’s code written AFTER T1’s. VERSION 1:int threadNumber = 1;startThreads();*** SIDE-BY-SIDE ***// T1:                                              // T2:while (!done) {                                     while (!done) {   // non-critical code goes here                      // non-critical code goes here   while (threadNumber == 2) ; // spin                 while (threadNumber == 1) ; // spin   // this line marks entering mutual exclusion        // this line marks entering mutual exclusion   // critical section code is here                    // critical section code is here   threadNumber = 2; // exiting mutual exclusion       threadNumber = 1; // exiting mutual exclusion   // more non-critical code goes here                 // more non-critical code goes here}                                                   }*** TOP AND BOTTOM ***// T1:while (!done) {   // non-critical code goes here   while (threadNumber == 2) ; // spin   // this line marks entering mutual exclusion   // critical section code is here   threadNumber = 2; // exiting mutual exclusion   // more non-critical code goes here}      // T2:while (!done) {   // non-critical code goes here   while (threadNumber == 1) ; // spin   // this line marks entering mutual exclusion   // critical section code is here   threadNumber = 1; // exiting mutual exclusion   // more non-critical code goes here}VERSION 2:boolean t1Inside = false;boolean t2Inside = false;startThreads();*** SIDE-BY-SIDE ***// T1:                                              // T2:while (!done) {                                     while (!done) {   while (t2Inside) ; // spin                          while (t1Inside) ; // spin   t1Inside = true; // this line marks                 t2Inside = true; // this line marks                    // entering mutual exclusion                        // entering mutual exclusion               // critical section code is here                    // critical section code is here   t1Inside = false; // exiting mutual exclusion       t2Inside = false; // exiting mutual exclusion   // more non-critical code goes here                 // more non-critical code goes here}                                                   }*** TOP AND BOTTOM ***// T1:while (!done) {   while (t2Inside) ; // spin   t1Inside = true; // this line marks                    // entering mutual exclusion   // critical section code is here   t1Inside = false; // exiting mutual exclusion   // more non-critical code goes here}// T2:while (!done) {   while (t1Inside) ; // spin   t2Inside = true; // this line marks                    // entering mutual exclusion               // critical section code is here   t2Inside = false; // exiting mutual exclusion   // more non-critical code goes here}                                                                            }