Question: 3 . ( 7 points ) ( a ) Given the following program in which two threads concurrently update one critical resource shared _ data

3.(7 points)
(a) Given the following program in which two threads concurrently update one critical resource shared_data without using lock(s). Theoretically, how many different final values may shared_data have? Please explain how each different value is attained by giving the running order of the statements (e.g.,9,10,11) of the two threads.
```
\l
\l
|
shared_data =1
rlock = threading.RLock()
def test(2):
global shared_data
for in in range(r); ; lock.aq uirell
rlockqqunt local = shared_data rlock, relone
Mrkreloselocal = local 2
shared_data = local
time.sleep(1) rlock, reqease
t1= threading.Thread(target = test, args =(2,))
t2= threading.Thread(target = test, args =(2,))
t1.start()
t2.start()
t1.join()
t2.join()
print(shared_data)
```
Theoretical Val. of shaved-data
3 . ( 7 points ) ( a ) Given the following

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!