diff options
Diffstat (limited to 'tests/fifo.lua')
-rw-r--r-- | tests/fifo.lua | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/tests/fifo.lua b/tests/fifo.lua index 47db4c9..bef60d5 100644 --- a/tests/fifo.lua +++ b/tests/fifo.lua | |||
@@ -6,11 +6,11 @@ | |||
6 | 6 | ||
7 | local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true} | 7 | local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true} |
8 | 8 | ||
9 | local linda= lanes.linda( "atom") | 9 | local linda = lanes.linda( "atom") |
10 | local atomic_inc= lanes.genatomic( linda, "FIFO_n" ) | 10 | local atomic_inc= lanes.genatomic( linda, "FIFO_n") |
11 | 11 | ||
12 | assert( atomic_inc()==1 ) | 12 | assert( atomic_inc()==1) |
13 | assert( atomic_inc()==2 ) | 13 | assert( atomic_inc()==2) |
14 | 14 | ||
15 | local function FIFO() | 15 | local function FIFO() |
16 | local my_channel= "FIFO"..atomic_inc() | 16 | local my_channel= "FIFO"..atomic_inc() |
@@ -18,32 +18,32 @@ local function FIFO() | |||
18 | return { | 18 | return { |
19 | -- Giving explicit 'nil' timeout allows numbers to be used as 'my_channel' | 19 | -- Giving explicit 'nil' timeout allows numbers to be used as 'my_channel' |
20 | -- | 20 | -- |
21 | send= function(self, ...) | 21 | send = function(self, ...) |
22 | linda:send( nil, my_channel, ... ) | 22 | linda:send( nil, my_channel, ...) |
23 | end, | 23 | end, |
24 | receive = function(self, timeout) | 24 | receive = function(self, timeout) |
25 | return linda:receive( timeout, my_channel ) | 25 | return linda:receive( timeout, my_channel) |
26 | end | 26 | end |
27 | } | 27 | } |
28 | end | 28 | end |
29 | 29 | ||
30 | local A= FIFO() | 30 | local A = FIFO() |
31 | local B= FIFO() | 31 | local B = FIFO() |
32 | 32 | ||
33 | print "Sending to A.." | 33 | print "Sending to A.." |
34 | A:send( 1,2,3,4,5 ) | 34 | A:send( 1,2,3,4,5) |
35 | 35 | ||
36 | print "Sending to B.." | 36 | print "Sending to B.." |
37 | B:send( 'a','b','c' ) | 37 | B:send( 'a','b','c') |
38 | 38 | ||
39 | print "Reading A.." | 39 | print "Reading A.." |
40 | print( A:receive( 1.0 ) ) | 40 | print( A:receive( 1.0)) |
41 | 41 | ||
42 | print "Reading B.." | 42 | print "Reading B.." |
43 | print( B:receive( 2.0 ) ) | 43 | print( B:receive( 2.0)) |
44 | 44 | ||
45 | -- Note: A and B can be passed between threads, or used as upvalues | 45 | -- Note: A and B can be passed between threads, or used as upvalues |
46 | -- by multiple threads (other parts will be copied but the 'linda' | 46 | -- by multiple threads (other parts will be copied but the 'linda' |
47 | -- handle is shared userdata and will thus point to the single place) | 47 | -- handle is shared userdata and will thus point to the single place) |
48 | lanes.timer_lane:cancel() | 48 | lanes.timer_lane:cancel() -- hard cancel, 0 timeout |
49 | lanes.timer_lane:join() \ No newline at end of file | 49 | lanes.timer_lane:join() \ No newline at end of file |