Question: 7. (12 marks) Assume the following: (a) Four (4) processes: P1, P2, P3, P4 share the following data: Shared Data Data set Semaphore seml initialized

7. (12 marks) Assume the following: (a) Four (4) processes: P1, P2, P3, P4 share the following data: Shared Data Data set Semaphore seml initialized to 1; Semaphore sem2 initialized to 1; Integer xl initialized to 0; Integer x2 initialized to 0; (b) The code for process Pi is follows: /* line 1: *7 do { /* line 2: */ wait (sem1); /* line 3: */ x1 = x2 ; /* line 4: * signal (sem1); /* line 5: */ } while (true); (c) Process P2, process P3, and process P4 have the same code, which is as follows: /* line 6: */ wait (sem2); /* line 7: */ x1 = x1 + 36; /* line 8: */ x2++; /* line 9: */ if (x2 = 1) /* line 10: */ wait (sem1); /* line 11: */ signal (sem2); /* line 12 */ x1 = x1 - 3; /* line 13: */ wait (sem2); /* line 14: *7 x2--; /* line 15: */ if (x2 == 0) /* line 16: */ signal (semi); /* line 17: */ signal (sem2); Suppose that the following sequence of events happen: (a) Process Pl starts executing. (b) At some time tl, process Pl completes executing line 2 of the code above. (c) Also at time t1, processes P2, P3, P4, start executing, and each of them will try to execute as much of its code as it can before process PI starts to execute line 4 of the code above. (d) After (c), at some time t2, process PI starts to execute line 4 of the code above; and completes executing line 4, at time t3. (e) After (d), at some time t4, processes P2, P3, P4 will continue to execute and will try to execute as much as of its code as it can before Pl starts to execute line 2 of the code above. You are required to explain in detail what possible values could the integer variable xl have after e) and before Pl starts to execute line 2 of the code above. (Marks will be deducted for wrong answers, so do not write answers that are only guesses.) 7. (12 marks) Assume the following: (a) Four (4) processes: P1, P2, P3, P4 share the following data: Shared Data Data set Semaphore seml initialized to 1; Semaphore sem2 initialized to 1; Integer xl initialized to 0; Integer x2 initialized to 0; (b) The code for process Pi is follows: /* line 1: *7 do { /* line 2: */ wait (sem1); /* line 3: */ x1 = x2 ; /* line 4: * signal (sem1); /* line 5: */ } while (true); (c) Process P2, process P3, and process P4 have the same code, which is as follows: /* line 6: */ wait (sem2); /* line 7: */ x1 = x1 + 36; /* line 8: */ x2++; /* line 9: */ if (x2 = 1) /* line 10: */ wait (sem1); /* line 11: */ signal (sem2); /* line 12 */ x1 = x1 - 3; /* line 13: */ wait (sem2); /* line 14: *7 x2--; /* line 15: */ if (x2 == 0) /* line 16: */ signal (semi); /* line 17: */ signal (sem2); Suppose that the following sequence of events happen: (a) Process Pl starts executing. (b) At some time tl, process Pl completes executing line 2 of the code above. (c) Also at time t1, processes P2, P3, P4, start executing, and each of them will try to execute as much of its code as it can before process PI starts to execute line 4 of the code above. (d) After (c), at some time t2, process PI starts to execute line 4 of the code above; and completes executing line 4, at time t3. (e) After (d), at some time t4, processes P2, P3, P4 will continue to execute and will try to execute as much as of its code as it can before Pl starts to execute line 2 of the code above. You are required to explain in detail what possible values could the integer variable xl have after e) and before Pl starts to execute line 2 of the code above. (Marks will be deducted for wrong answers, so do not write answers that are only guesses.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
