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} }
Category: Uncategorized
Is it possible for a process to transition directly from the…
Is it possible for a process to transition directly from the suspended-ready state to the suspended-blocked state? Explain why or why not.
What is a “real-time” system? Give one example of a real-tim…
What is a “real-time” system? Give one example of a real-time system that is NOT mission-critical or business critical and explain why this example is real-time.
Explain the concept of a load balancing.
Explain the concept of a load balancing.
What is the role of the Frontside Bus (FSB) in a computer ex…
What is the role of the Frontside Bus (FSB) in a computer executing instructions?
Why is the functionality of a PCB a good choice for OS funct…
Why is the functionality of a PCB a good choice for OS functionality to build into hardware? Note: PCB here refers to a Process Control Block, do NOT confuse this with a printed circuit board.
Say which of the following is true and fully explain every p…
Say which of the following is true and fully explain every part of the answer (the cases where the statement applies and the cases where it does not). Mutual exclusion must be enforced in the following scenarios: 1. On any shared memory, whether it is modifiable or not. 2. On any modifiable memory, whether is it shared or not. 3. Even on memory that is neither shared nor modifiable. 4. Only on memory that is both shared and modifiable.
Explain the terms master and slave in a distributed system….
Explain the terms master and slave in a distributed system. In your answer include an example of something a master has to do that a slave does not, and something a slave has to do that a master does not.
Explain how threading can be used to improve the user experi…
Explain how threading can be used to improve the user experience of waiting for a program to run all of the preliminary tasks that must occur for the program can actually be used. Obviously, this question is asking for something that specifically relates to the given scenario, not just a general advantage of multithreading that applies to all scenarios of a programming running.
What is a peripheral device and what is its relationship to…
What is a peripheral device and what is its relationship to operating systems?