##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: September, 2016 # Modified: 2016-10-10/16:46-0400 ##+ # # mutex.icn, Demonstrate mutually exclusive gating variables. # global x procedure main() x := 0 mtx := mutex() T1 := thread report(mtx) T2 := thread other(mtx) # due to the nature of threading # the values displayed in report # might be 1,2,3,4 or 1,10,11,12 or 1,2,11,12 etc wait(T1 | T2) # final result will always be 12 write("x is ", x) end # increment and report procedure report(mtx) every 1 to 4 do { critical mtx : x := x + 1 write(x) } end # just increment procedure other(mtx) every 1 to 8 do critical mtx : x := x + 1 end