1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: dlists kernel threads concurrency.conditions accessors ;
6 TUPLE: flag value threads ;
8 : <flag> ( -- flag ) f <dlist> flag boa ;
10 : raise-flag ( flag -- )
11 dup value>> [ drop ] [ t >>value threads>> notify-all ] if ;
13 : wait-for-flag-timeout ( flag timeout -- )
14 over value>> [ 2drop ] [ [ threads>> ] dip "flag" wait ] if ;
16 : wait-for-flag ( flag -- )
17 f wait-for-flag-timeout ;
19 : lower-flag ( flag -- )
20 [ wait-for-flag ] [ f >>value drop ] bi ;