Question: A shared variable A , initialized to 0, is operated on by 4 processes w,x,y,z. Processes w and x increment A by 1 while processes
A shared variable A , initialized to 0, is operated on by 4 processes w,x,y,z. Processes w and x increment A by 1 while processes y and z decrement it by 2. Each process before reading performs a wait on a semaphore S and signal on S after store or writing.
Ex: Process W () {
wait(S);
Read A to a local var;
increment local var by 1;
Store value from local var to A.
signal(S);
}
Same code for process x. For y,z, the increment is changed to decrement by 2.
i. Find what would be the MAX value of A after all the 4 processes complete execution Fully, if Semaphore S were to be initialized with 1. Explain your answer with the ordering of the processes.
ii. What would be the MAX value of A after all 4 processes complete fully, if Semaphore S were to be initialized with value 2. Explain your answer with the ordering of the processes.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
