1 ! Copyright (C) 2005 Chris Double. All Rights Reserved.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel threads vectors arrays sequences namespaces make
4 tools.test continuations deques strings math words match
5 quotations concurrency.messaging concurrency.mailboxes
6 concurrency.count-downs accessors ;
7 IN: concurrency.messaging.tests
9 [ ] [ my-mailbox data>> clear-deque ] unit-test
13 receive "received" swap reply-synchronous
14 ] "Synchronous test" spawn
15 "sent" swap send-synchronous
23 [ 2 mod 0 = not ] receive-if
30 ] "Linked test" spawn-linked drop
32 ] [ error>> "crash" = ] must-fail-with
34 MATCH-VARS: ?from ?to ?value ;
40 : counter ( value -- value ? )
42 { { increment ?value } [ ?value + t ] }
43 { { decrement ?value } [ ?value - t ] }
44 { { value ?from } [ dup ?from send t ] }
49 [ 0 [ counter ] loop ] "Counter" spawn "counter" set
50 { increment 10 } "counter" get send
51 { decrement 15 } "counter" get send
52 [ value , self , ] { } make "counter" get send
54 exit "counter" get send
59 ! 1 <count-down> "c" set
64 ! ] "Bad synchronous send" spawn "t" set
66 ! [ 3 "t" get send-synchronous ] must-fail