Question: 4. Pseudocode for the exchange function, and a solution to the critical section (CS) problem based on its use is given. Assume the call to

4. Pseudocode for the exchange function, and a solution to the critical section (CS) problem based on its use is given. Assume the call to spawn spawns two threads, one that runs P with parameter 1 and the other that runs P with parameter 2. [10 marks total void exchange( int register, int memory int temp; temp = memory ; memory = register; register temp; void P int i) int bolt; /I global variable int keyi -1; while true )f void main) f exchange keyi, bolt; while keyi- 0 // code for critical section (CS) here exchange ( keyi, bolt); /*remainder bolt-0; spawn P(1), P(2) ); (a) Show that if the exchange instruction is not executed atomically, mutual exclusion (ME) could be violated, i.e., give an interleaving of P(1) and P(2) that shows ME within the CS can be violated. [5 marks] (b) State the requirements for a solution to the critical section (CS) problem, and briefly discuss if the solution above satisfies each requirement. [5 marks] 4. Pseudocode for the exchange function, and a solution to the critical section (CS) problem based on its use is given. Assume the call to spawn spawns two threads, one that runs P with parameter 1 and the other that runs P with parameter 2. [10 marks total void exchange( int register, int memory int temp; temp = memory ; memory = register; register temp; void P int i) int bolt; /I global variable int keyi -1; while true )f void main) f exchange keyi, bolt; while keyi- 0 // code for critical section (CS) here exchange ( keyi, bolt); /*remainder bolt-0; spawn P(1), P(2) ); (a) Show that if the exchange instruction is not executed atomically, mutual exclusion (ME) could be violated, i.e., give an interleaving of P(1) and P(2) that shows ME within the CS can be violated. [5 marks] (b) State the requirements for a solution to the critical section (CS) problem, and briefly discuss if the solution above satisfies each requirement. [5 marks]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
