resource nested_in_example() op increment(amount : int), decrement(amount : int) var num_incs : int := 10, num_decs : int := 10 getarg(1, num_incs); getarg(2, num_decs) process inc(i := 1 to num_incs) var amount : int do true -> nap(int(random(i*1000))) amount := int(random(i*10)) write("inc", i, "wants to inc by", amount) increment(amount) od end inc process dec(j := 1 to num_decs) var amount : int do true -> nap(int(random(j*1000))) amount := int(random(j*10)) write("dec", j, "wants to dec by", amount) decrement(amount) od end dec var value : int := 110; getarg(3, value) var run_time : int := 60; getarg(4, run_time) write("simulation starting with", num_incs, "incs,", num_decs, "decs,", value, "value, and", run_time, "run_time") process server do true -> in increment(amount) st amount > 50 -> # put this branch first, else value +:= amount # next branch always gets it write("WOW! Parents! value +:=", amount, "is", value) [] increment(amount) -> value +:= amount write("value +:=", amount, "is", value) [] decrement(amount) -> # never let value be decremented below 100 do value - amount < 100 -> in increment(amount2) -> value +:= amount2 + 10 write("value +:=", amount2, "+ 10 bonus is", value) ni od value -:= amount write("value -:=", amount, "is", value) [] else -> write("server is idle so nap..."); nap(1000) ni od end server nap(1000*run_time); write("must stop now"); stop end nested_in_example /* ............... Example compile and run(s) % sr -o nested_ins nested_ins.sr % ./nested_ins 10 10 110 5 simulation starting with 10 incs, 10 decs, 110 value, and 5 run_time server is idle so nap... inc 6 wants to inc by 11 dec 1 wants to dec by 3 dec 5 wants to dec by 24 inc 1 wants to inc by 0 dec 3 wants to dec by 20 dec 2 wants to dec by 16 inc 4 wants to inc by 18 value +:= 11 is 121 value -:= 3 is 118 value +:= 0 + 10 bonus is 128 value -:= 24 is 104 value +:= 18 + 10 bonus is 132 value -:= 20 is 112 dec 1 wants to dec by 2 inc 2 wants to inc by 17 value +:= 17 + 10 bonus is 139 value -:= 16 is 123 value -:= 2 is 121 server is idle so nap... inc 3 wants to inc by 1 dec 1 wants to dec by 8 inc 2 wants to inc by 18 inc 1 wants to inc by 3 inc 5 wants to inc by 0 value +:= 1 is 122 value -:= 8 is 114 value +:= 18 is 132 value +:= 3 is 135 value +:= 0 is 135 server is idle so nap... dec 1 wants to dec by 9 dec 7 wants to dec by 50 inc 2 wants to inc by 19 dec 3 wants to dec by 29 inc 1 wants to inc by 9 dec 2 wants to dec by 9 inc 6 wants to inc by 43 dec 6 wants to dec by 41 value -:= 9 is 126 value +:= 19 + 10 bonus is 155 value -:= 50 is 105 value +:= 9 + 10 bonus is 124 value +:= 43 + 10 bonus is 177 value -:= 29 is 148 value -:= 9 is 139 dec 1 wants to dec by 1 dec 4 wants to dec by 17 dec 3 wants to dec by 24 inc 1 wants to inc by 2 value +:= 2 + 10 bonus is 151 value -:= 41 is 110 value -:= 1 is 109 inc 10 wants to inc by 95 value +:= 95 + 10 bonus is 214 value -:= 17 is 197 value -:= 24 is 173 server is idle so nap... inc 2 wants to inc by 19 inc 8 wants to inc by 17 inc 1 wants to inc by 3 inc 4 wants to inc by 0 dec 2 wants to dec by 5 inc 6 wants to inc by 58 inc 3 wants to inc by 23 dec 1 wants to dec by 2 inc 7 wants to inc by 69 value +:= 19 is 192 value +:= 17 is 209 value +:= 3 is 212 value +:= 0 is 212 value -:= 5 is 207 WOW! Parents! value +:= 58 is 265 value +:= 23 is 288 value -:= 2 is 286 WOW! Parents! value +:= 69 is 355 server is idle so nap... dec 1 wants to dec by 9 inc 3 wants to inc by 7 must stop now */