Question: Suppose proc 1 and proc 2 run in two separate threads and that each procedure is called in its respective thread exactly once. Variables x

Suppose proc1 and proc2 run in two separate threads and that each procedure is called in its respective thread exactly once. Variables x and a are global and shared between threads and x is initialized to 0. Further, assume the increment and decrement operations are atomic. The calls to proc3 in proc1 and proc2 should be replaced with calls to proc3a and proc3b depending on the part of the question. a) If proc1 and proc2 call proc3a in lines 10 and 18, is the final value of global variable x guaranteed to be 0? Justify your answer. b) What if proc1 and proc2 call proc3b? Justify your answer. c) With proc1 and proc2 still calling proc3b, modify proc1 and proc2 with condition variable go to guarantee the final value of x is 2. Specifically, give the lines where pthread_cond_wait and pthread_cond_signal should be inserted into the code listing. Justify your answer briefly. Make the assumption that proc1 acquires lock_a before proc2. Also recall that pthread_cond_wait(&go, &lock_a); will temporarily release lock_a and block the calling thread until pthread_cond_signal(&go); is called in another thread, at which point the waiting thread will be unblocked and reacquire lock_a.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!