Question: Need help with number 2! 4. Synchronization (26 points) two threads that run concurrently. The code for the two threads are follows The process has
4. Synchronization (26 points) two threads that run concurrently. The code for the two threads are follows The process has ads are s hown as Thread A: (Al) yl=x; (A2) yl -yl +1; (A3) x=yl; Thread B: (BI) y2 =x; (B2) y2 - y2+ 2 (B3) x- y2; Suppose x is a global variable shared by the two threads and is initialized to 0. 1) ution. List all the possible Also briefly explain how x gets each of the values you listed at the end of execution. (hint: think about the execution orders of A1-A3 and B1-B3) Alurocessg cess is revrredl 2) To eliminate the potential data races in the above case, how do you modify the code of thread A and B? Given that you have a binary semaphore:,mutex, which is ly initialized to 1 and two operations, wait (or down, P) and or t
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
