comparison tests/roundTrip.ur @ 728:2197f0e24a9f

Avoid thread death via message receive
author Adam Chlipala <adamc@hcoop.net>
date Thu, 16 Apr 2009 13:00:40 -0400
parents
children 7c6b6c3c7b79
comparison
equal deleted inserted replaced
727:ba4c230b7231 728:2197f0e24a9f
1 table channels : { Client : client, Channel : channel (string * int * float) }
2 PRIMARY KEY Client
3
4 fun writeBack v =
5 me <- self;
6 r <- oneRow (SELECT channels.Channel FROM channels WHERE channels.Client = {[me]});
7 send r.Channels.Channel v
8
9 fun main () =
10 me <- self;
11 ch <- channel;
12 dml (INSERT INTO channels (Client, Channel) VALUES ({[me]}, {[ch]}));
13
14 buf <- Buffer.create;
15
16 let
17 fun receiverA () =
18 v <- recv ch;
19 Buffer.write buf ("A:(" ^ v.1 ^ ", " ^ show v.2 ^ ", " ^ show v.3 ^ ")");
20 receiverA ()
21
22 fun receiverB () =
23 v <- recv ch;
24 Buffer.write buf ("B:(" ^ v.1 ^ ", " ^ show v.2 ^ ", " ^ show v.3 ^ ")");
25 error <xml>Bail out!</xml>;
26 receiverB ()
27
28 fun sender s n f =
29 sleep 9;
30 writeBack (s, n, f);
31 sender (s ^ "!") (n + 1) (f + 1.23)
32 in
33 return <xml><body onload={spawn (receiverA ()); spawn (receiverB ()); sender "" 0 0.0}>
34 <dyn signal={Buffer.render buf}/>
35 </body></xml>
36 end