aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/track_lanes.lua72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/track_lanes.lua b/tests/track_lanes.lua
new file mode 100644
index 0000000..46cfdad
--- /dev/null
+++ b/tests/track_lanes.lua
@@ -0,0 +1,72 @@
1local lanes = require "lanes" .configure{ with_timers = false, track_lanes = true}
2
3local wait
4do
5 local linda = lanes.linda()
6 wait = function( seconds_)
7 linda:receive( seconds_, "dummy_key")
8 end
9end
10
11print "hello"
12
13local track = function( title_)
14 print( title_)
15 for k, v in pairs( lanes.threads())
16 do
17 print( k, v.name, v.status)
18 end
19 print( "\n")
20end
21
22local sleeper = function( name_, seconds_)
23 -- print( "entering '" .. name_ .. "'")
24 local lanes = require "lanes"
25 -- no set_debug_threadname in main thread
26 if set_debug_threadname
27 then
28 -- print( "set_debug_threadname('" .. name_ .. "')")
29 set_debug_threadname( name_)
30 end
31 -- suspend the lane for the specified duration with a failed linda read
32 wait( seconds_)
33 -- print( "exiting '" .. name_ .. "'")
34end
35
36-- sleeper( "main", 1)
37
38-- the generator
39local g = lanes.gen( "*", sleeper)
40
41-- start a forever-waiting lane (nil timeout)
42g( "forever")
43
44-- start a lane that will last 2 seconds
45g( "two_seconds", 2)
46
47-- give a bit of time to reach the linda waiting call
48wait( 0.1)
49
50-- list the known lanes
51track( "============= START")
52
53-- wait until "two_seconds has completed"
54wait(2.1)
55
56track( "============= two_seconds dead")
57
58-- this will collect the completed lane (and remove it from the tracking queue)
59-- collectgarbage()
60
61-- track( "============= two_seconds dead (after collectgarbage)")
62
63-- start another lane that will last 2 seconds, with the same name
64g( "two_seconds", 2)
65
66-- give a bit of time to reach the linda waiting call
67wait( 0.1)
68
69-- list the known lanes
70track( "============= ANOTHER")
71
72print "done" \ No newline at end of file