resource race_2_processes() var auditor_nap : int := 1 var num_accounts : int := 10000 var initial_value : real := 1000.00 var savings[1:num_accounts] : real := ([num_accounts] initial_value) sem mutex := 1 write("bank is open with", num_accounts*initial_value, "in funds") process atm var from_acc, to_acc : int var amount : real do true -> from_acc := int(random(1,num_accounts+1)) to_acc := int(random(1,num_accounts+1)) amount := random(savings[from_acc]) P(mutex) # pre-protocol: enter CRITICAL SECTION savings[from_acc] -:= amount savings[to_acc] +:= amount V(mutex) # post-protocol: exit CRITICAL SECTION od end atm process auditor var total : real do true -> nap(1000*auditor_nap) P(mutex) # pre-protocol: enter CRITICAL SECTION total := 0 fa i := 1 to num_accounts -> total +:= savings[i] af V(mutex) # post-protocol: exit CRITICAL SECTION write("age()=", age(), "total is ", total) od end auditor end race_2_processes /* ............... Example compile and run(s) % sr -o race race_fixed.sr % ./race bank is open with 1.00000e+07 in funds age()= 1460 total is 1.00000e+07 age()= 2894 total is 1.00000e+07 age()= 4393 total is 1.00000e+07 age()= 5821 total is 1.00000e+07 age()= 7071 total is 1.00000e+07 age()= 8300 total is 1.00000e+07 age()= 9607 total is 1.00000e+07 age()= 10948 total is 1.00000e+07 age()= 12269 total is 1.00000e+07 age()= 13576 total is 1.00000e+07 age()= 14878 total is 1.00000e+07 age()= 16157 total is 1.00000e+07 ^C */