aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2021-06-16 18:41:14 +0200
committerBenoit Germain <bnt.germain@gmail.com>2021-06-16 18:41:14 +0200
commit5875fe44ba7a240dd101f954c7dc83337a0c2cef (patch)
tree5c53b56b750c135163d462a39217fb88f8741ed6 /tests
parent21b2ac762ff8a5926872963aa2fd8feeb1bf3b39 (diff)
downloadlanes-5875fe44ba7a240dd101f954c7dc83337a0c2cef.tar.gz
lanes-5875fe44ba7a240dd101f954c7dc83337a0c2cef.tar.bz2
lanes-5875fe44ba7a240dd101f954c7dc83337a0c2cef.zip
changed lanes.threads() output so that several lanes with the same name don't clobber each other in the result table
In the original implementations, the debug name was used as key, which meant that several lanes using the same name would cause only the oldest non-collected one to be listed in the results. Now the result is an array of tuples.
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