##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: October 2016 # Modified: 2016-10-08/19:22-0400 ##+ # # condvar.icn, demonstrate a threading condition variable # # taken from the Programming with Unicon book, page 146 procedure main() mtx := mutex() L := mutex([], mtx) cv := condvar(mtx) p := thread produce(L, cv) c := thread consume(L, cv) every wait(p | c) end procedure produce(L, cv) every put(L, !10) & *L=1 & signal(cv) end procedure consume(L, cv) i := 0 while i < 10 do if x := get(L) then i +:= 1 & write(x) else critical cv: until *L>0 do wait(cv) end