aboutsummaryrefslogtreecommitdiff
path: root/tests/fifo.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/fifo.lua')
-rw-r--r--tests/fifo.lua32
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
7local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true} 7local lanes = require "lanes".configure{shutdown_timeout=3,with_timers=true}
8 8
9local linda= lanes.linda( "atom") 9local linda = lanes.linda( "atom")
10local atomic_inc= lanes.genatomic( linda, "FIFO_n" ) 10local atomic_inc= lanes.genatomic( linda, "FIFO_n")
11 11
12assert( atomic_inc()==1 ) 12assert( atomic_inc()==1)
13assert( atomic_inc()==2 ) 13assert( atomic_inc()==2)
14 14
15local function FIFO() 15local 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 }
28end 28end
29 29
30local A= FIFO() 30local A = FIFO()
31local B= FIFO() 31local B = FIFO()
32 32
33print "Sending to A.." 33print "Sending to A.."
34A:send( 1,2,3,4,5 ) 34A:send( 1,2,3,4,5)
35 35
36print "Sending to B.." 36print "Sending to B.."
37B:send( 'a','b','c' ) 37B:send( 'a','b','c')
38 38
39print "Reading A.." 39print "Reading A.."
40print( A:receive( 1.0 ) ) 40print( A:receive( 1.0))
41 41
42print "Reading B.." 42print "Reading B.."
43print( B:receive( 2.0 ) ) 43print( 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)
48lanes.timer_lane:cancel() 48lanes.timer_lane:cancel() -- hard cancel, 0 timeout
49lanes.timer_lane:join() \ No newline at end of file 49lanes.timer_lane:join() \ No newline at end of file