From 512f4c0b46ea5cc359e673b7379cd81925863121 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 14 Mar 2025 14:53:09 +0100 Subject: Give a name to all lanes in the tests --- deep_userdata_example/deeptest.lua | 1 + tests/appendud.lua | 2 +- tests/atexit.lua | 4 ++-- tests/basic.lua | 24 +++++++++++----------- tests/cancel.lua | 10 ++++----- tests/cyclic.lua | 6 +++--- tests/ehynes.lua | 2 +- tests/error.lua | 2 +- tests/fibonacci.lua | 2 +- tests/finalizer.lua | 2 +- tests/func_is_string.lua | 6 +++--- tests/hangtest.lua | 2 +- tests/irayo_closure.lua | 2 +- tests/irayo_recursive.lua | 2 +- tests/keeper.lua | 2 +- tests/lanes_as_upvalue.lua | 2 +- tests/launchtest.lua | 2 +- tests/linda_perf.lua | 4 ++-- tests/manual_register.lua | 2 +- tests/nameof.lua | 2 +- tests/objects.lua | 2 +- tests/parallel_os_calls.lua | 16 +++++++-------- tests/perftest.lua | 4 ++-- tests/pingpong.lua | 4 ++-- tests/protect_allocator.lua | 2 +- tests/protectproxy.lua | 2 +- tests/recursive.lua | 2 +- tests/require.lua | 4 ++-- tests/rupval.lua | 2 +- tests/tobeclosed.lua | 4 ++-- tests/track_lanes.lua | 2 +- unit_tests/embedded_tests.cpp | 2 +- unit_tests/init_and_shutdown.cpp | 1 + unit_tests/lane_tests.cpp | 2 +- unit_tests/scripts/coro/basics.lua | 2 +- unit_tests/scripts/lane/cooperative_shutdown.lua | 6 +++--- unit_tests/scripts/lane/stdlib_naming.lua | 2 +- unit_tests/scripts/lane/tasking_basic.lua | 2 +- unit_tests/scripts/lane/tasking_cancelling.lua | 8 ++++---- .../scripts/lane/tasking_comms_criss_cross.lua | 2 +- unit_tests/scripts/lane/tasking_communications.lua | 2 +- unit_tests/scripts/lane/tasking_error.lua | 2 +- unit_tests/scripts/lane/tasking_join_test.lua | 2 +- .../scripts/lane/tasking_send_receive_code.lua | 2 +- unit_tests/scripts/lane/uncooperative_shutdown.lua | 2 +- 45 files changed, 82 insertions(+), 80 deletions(-) diff --git a/deep_userdata_example/deeptest.lua b/deep_userdata_example/deeptest.lua index 6ef4b74..37136cd 100644 --- a/deep_userdata_example/deeptest.lua +++ b/deep_userdata_example/deeptest.lua @@ -82,6 +82,7 @@ local performTest = function( obj_) local g = lanes.gen( "package" , { + name = 'auto', required = { "deep_userdata_example"} -- we will transfer userdata created by this module, so we need to make this lane aware of it } , function( arg_, t_) diff --git a/tests/appendud.lua b/tests/appendud.lua index f510c8b..f6f99c1 100644 --- a/tests/appendud.lua +++ b/tests/appendud.lua @@ -42,7 +42,7 @@ function appendud(tab, ud) -- ('tab' is passed over lanes by value, not by reference) end -local t,err= lanes.gen( "base,io", appendud )( _tab, _ud ) -- create & launch a thread +local t,err= lanes.gen( "base,io", { name = 'auto'}, appendud )( _tab, _ud ) -- create & launch a thread assert(t) assert(not err) diff --git a/tests/atexit.lua b/tests/atexit.lua index 9fc3070..ba10d3b 100644 --- a/tests/atexit.lua +++ b/tests/atexit.lua @@ -16,8 +16,8 @@ local g = function() print "User cancellation detected!" end -local genF = lanes.gen( "", {globals = {threadName = "mylane"}}, f) -local genG = lanes.gen( "", g) +local genF = lanes.gen( "", {name = 'auto', globals = {threadName = "mylane"}}, f) +local genG = lanes.gen( "", { name = 'auto'}, g) -- launch a good batch of free running lanes diff --git a/tests/basic.lua b/tests/basic.lua index 820d3c8..068dc25 100644 --- a/tests/basic.lua +++ b/tests/basic.lua @@ -15,7 +15,7 @@ local lanes = require_lanes_result_1 local require_assert_result_1, require_assert_result_2 = require "assert" -- assert.fails() print("require_assert_result:", require_assert_result_1, require_assert_result_2) -local lanes_gen= assert(lanes.gen) +local lanes_gen assert(lanes.gen) local lanes_linda = assert(lanes.linda) local tostring= assert(tostring) @@ -86,7 +86,7 @@ local function task(a, b, c) return v, hey end -local task_launch= lanes_gen("", { globals={hey=true}, gc_cb = gc_cb}, task) +local task_launch= lanes.gen("", { name = 'auto', globals={hey=true}, gc_cb = gc_cb }, task) -- base stdlibs, normal priority -- 'task_launch' is a factory of multithreaded tasks, we can launch several: @@ -126,7 +126,7 @@ collectgarbage() PRINT("\n\n", "---=== Tasking (cancelling) ===---", "\n\n") -local task_launch2= lanes_gen("", { globals={hey=true}, gc_cb = gc_cb}, task) +local task_launch2= lanes.gen("", { name = 'auto', globals={hey=true}, gc_cb = gc_cb }, task) local N=999999999 local lane9= task_launch2(1,N,1) -- huuuuuuge... @@ -177,7 +177,7 @@ local wait_send = function() a,b = limited:send("key", "bybye") -- infinite timeout, returns only when lane is cancelled end -local wait_send_lane = lanes.gen("*", wait_send)() +local wait_send_lane = lanes.gen("*", { name = 'auto' }, wait_send)() repeat until wait_send_lane.status == "waiting" print "wait_send_lane is waiting" wait_send_lane:cancel() -- hard cancel, 0 timeout @@ -190,7 +190,7 @@ local wait_receive = function() k, v = limited:receive("dummy") -- infinite timeout, returns only when lane is cancelled end -local wait_receive_lane = lanes.gen("*", wait_receive)() +local wait_receive_lane = lanes.gen("*", { name = 'auto' }, wait_receive)() repeat until wait_receive_lane.status == "waiting" print "wait_receive_lane is waiting" wait_receive_lane:cancel() -- hard cancel, 0 timeout @@ -203,7 +203,7 @@ local wait_receive_batched = function() k, v1, v2 = limited:receive(limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled end -local wait_receive_batched_lane = lanes.gen("*", wait_receive_batched)() +local wait_receive_batched_lane = lanes.gen("*", { name = 'auto' }, wait_receive_batched)() repeat until wait_receive_batched_lane.status == "waiting" print "wait_receive_batched_lane is waiting" wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout @@ -275,7 +275,7 @@ local function PEEK(...) return linda:get("<-", ...) end local function SEND(...) local _res, _err = linda:send("->", ...) assert(_res == true and _err == nil) end local function RECEIVE() local k,v = linda:receive(1, "<-") return v end -local comms_lane = lanes_gen("io", {gc_cb = gc_cb, name = "auto"}, chunk)(linda) -- prepare & launch +local comms_lane = lanes.gen("io", { name = 'auto', gc_cb = gc_cb }, chunk)(linda) -- prepare & launch SEND(1); WR("main ", "1 sent\n") SEND(2); WR("main ", "2 sent\n") @@ -355,7 +355,7 @@ local function coro_f(_x) return true end -assert.fails(function() lanes_gen("xxx", {gc_cb = gc_cb}, io_os_f) end) +assert.fails(function() lanes_gen("xxx", {name = 'auto', gc_cb = gc_cb }, io_os_f) end) local stdlib_naming_tests = { @@ -371,7 +371,7 @@ local stdlib_naming_tests = } for _, t in ipairs(stdlib_naming_tests) do - local f= lanes_gen(t[1], {gc_cb = gc_cb}, t[2]) -- any delimiter will do + local f= lanes.gen(t[1], { name = 'auto', gc_cb = gc_cb }, t[2]) -- any delimiter will do assert(f(t[1])[1]) end @@ -386,7 +386,7 @@ PRINT("\n\n", "---=== Comms criss cross ===---", "\n\n") -- We make two identical lanes, which are using the same Linda channel. -- -local tc= lanes_gen("io", {gc_cb = gc_cb}, +local tc = lanes.gen("io", { name = 'auto', gc_cb = gc_cb }, function(linda, ch_in, ch_out) lane_threadname("criss cross " .. ch_in .. " -> " .. ch_out) local function STAGE(str) @@ -453,7 +453,7 @@ local function chunk2(linda) end local linda = lanes_linda("auto") -local t2= lanes_gen("debug,string,io", {gc_cb = gc_cb}, chunk2)(linda) -- prepare & launch +local t2 = lanes.gen("debug,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch linda:send("down", function(linda) linda:send("up", "ready!") end, "ok") -- wait to see if the tiny function gets executed @@ -486,7 +486,7 @@ PRINT("\n\n", "---=== :join test ===---", "\n\n") -- (unless [1..n] has been read earlier, in which case it would seemingly -- work). -local S= lanes_gen("table", {gc_cb = gc_cb}, +local S = lanes.gen("table", { name = 'auto', gc_cb = gc_cb }, function(arg) lane_threadname "join test lane" set_finalizer(function() end) diff --git a/tests/cancel.lua b/tests/cancel.lua index 5862c85..80e6c6a 100644 --- a/tests/cancel.lua +++ b/tests/cancel.lua @@ -160,7 +160,7 @@ end if not next(which_tests) or which_tests.linda then remaining_tests.linda = nil print "\n\n####################################################################\nbegin linda cancel test\n" - h = generator("*", laneBody)("receive", nil) -- start an infinite wait on the linda + h = generator("*", { name = 'auto' }, laneBody)("receive", nil) -- start an infinite wait on the linda print "wait 1s" SLEEP(1) @@ -181,7 +181,7 @@ end if not next(which_tests) or which_tests.soft then remaining_tests.soft = nil print "\n\n####################################################################\nbegin soft cancel test\n" - h = generator("*", protectedBody)("receive") -- start an infinite wait on the linda + h = generator("*", { name = 'auto' }, protectedBody)("receive") -- start an infinite wait on the linda print "wait 1s" SLEEP(1) @@ -205,7 +205,7 @@ end if not next(which_tests) or which_tests.hook then remaining_tests.hook = nil print "\n\n####################################################################\nbegin hook cancel test\n" - h = generator("*", protectedBody)("get", 300000) + h = generator("*", { name = 'auto' }, protectedBody)("get", 300000) print "wait 2s" SLEEP(2) @@ -222,7 +222,7 @@ end if not next(which_tests) or which_tests.hard then remaining_tests.hard = nil print "\n\n####################################################################\nbegin hard cancel test\n" - h = lanes.gen("*", protectedBody)("receive", nil) -- infinite timeout + h = lanes.gen("*", { name = 'auto' }, protectedBody)("receive", nil) -- infinite timeout -- wait 2s before cancelling the lane print "wait 2s" @@ -241,7 +241,7 @@ end if not next(which_tests) or which_tests.hard_unprotected then remaining_tests.hard_unprotected = nil print "\n\n####################################################################\nbegin hard cancel test with unprotected lane body\n" - h = generator("*", laneBody)("receive", nil) + h = generator("*", { name = 'auto' }, laneBody)("receive", nil) -- wait 2s before cancelling the lane print "wait 2s" diff --git a/tests/cyclic.lua b/tests/cyclic.lua index ed4bdba..ca4b9f5 100644 --- a/tests/cyclic.lua +++ b/tests/cyclic.lua @@ -31,7 +31,7 @@ local function lane1() assert( b[1]==a ) return true end -local L1= lanes.gen( "io", lane1 )() +local L1= lanes.gen( "io", { name = 'auto' }, lane1 )() -- ...running -- Getting the tables as arguments should also keep the linkage @@ -42,7 +42,7 @@ local function lane2( aa, bb ) assert( bb[1]==aa ) return true end -local L2= lanes.gen( "io", lane2 )( a, b ) +local L2= lanes.gen( "io", { name = 'auto' }, lane2 )( a, b ) -- ...running -- Really unnecessary, but let's try a directly recursive table @@ -55,7 +55,7 @@ local function lane3( cc ) assert( cc and cc.a==cc ) return true end -local L3= lanes.gen("io", lane3)(c) +local L3= lanes.gen("io", { name = 'auto' }, lane3)(c) -- Without a wait, exit from the main lane will close the process -- diff --git a/tests/ehynes.lua b/tests/ehynes.lua index cdcd5a5..e4b56a5 100644 --- a/tests/ehynes.lua +++ b/tests/ehynes.lua @@ -16,7 +16,7 @@ end local linda = lanes.linda() -- a linda message receiver -local receiver_gen = lanes.gen( 'base', 'os', 'string', 'io', +local receiver_gen = lanes.gen( 'base', 'os', 'string', 'io', { name = 'auto' }, function (message_name) PRINT_FMT( 'receiver for message %s entered', message_name ) local n = 1 diff --git a/tests/error.lua b/tests/error.lua index 243dd57..306c51d 100644 --- a/tests/error.lua +++ b/tests/error.lua @@ -87,7 +87,7 @@ end --################################################################################################## local start_lane = function(error_reporting_mode_, error_value_, finalizer_, finalizer_error_value_) - return lanes.gen("*", {error_trace_level = error_reporting_mode_}, lane_body)(error_value_, finalizer_, finalizer_error_value_) + return lanes.gen("*", { name = 'auto', error_trace_level = error_reporting_mode_ }, lane_body)(error_value_, finalizer_, finalizer_error_value_) end --################################################################################################## diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua index 7885ae6..2c043c3 100644 --- a/tests/fibonacci.lua +++ b/tests/fibonacci.lua @@ -44,7 +44,7 @@ local function fib( n ) else -- Splits into two; this task remains waiting for the results -- - local gen_f= lanes.gen( "*", fib) + local gen_f= lanes.gen( "*", { name = 'auto' }, fib) local n1=floor(n/2) +1 local n2=floor(n/2) -1 + n%2 diff --git a/tests/finalizer.lua b/tests/finalizer.lua index 8bf89b4..ac5ce8b 100644 --- a/tests/finalizer.lua +++ b/tests/finalizer.lua @@ -69,7 +69,7 @@ cleanup = function(err) end -- we need error_trace_level above "minimal" to get a stack trace out of h:join() -local lgen = lanes.gen("*", {error_trace_level = "basic"}, lane) +local lgen = lanes.gen("*", { name = 'auto', error_trace_level = "basic" }, lane) local do_test = function(error_) diff --git a/tests/func_is_string.lua b/tests/func_is_string.lua index a14c460..5de4c60 100644 --- a/tests/func_is_string.lua +++ b/tests/func_is_string.lua @@ -7,7 +7,7 @@ if _VERSION >= "Lua 5.4" then local lanes = require 'lanes' local r do - local h = lanes.gen('*', lanes.sleep)(0.5) + local h = lanes.gen('*', { name = 'auto' }, lanes.sleep)(0.5) r = h end -- h is closed here return r.status @@ -21,8 +21,8 @@ end local options = {globals = { b = 666 }} -local gen1 = lanes.gen("*", "return true, dofile('fibonacci.lua')") -local gen2 = lanes.gen(options, "return b") +local gen1 = lanes.gen("*", { name = 'auto' }, "return true, dofile('fibonacci.lua')") +local gen2 = lanes.gen(options, { name = 'auto' }, "return b") fibLane = gen1() lanes.sleep(0.1) diff --git a/tests/hangtest.lua b/tests/hangtest.lua index 0e44451..e48ff60 100644 --- a/tests/hangtest.lua +++ b/tests/hangtest.lua @@ -7,7 +7,7 @@ local lanes = require "lanes" local function ret(b) return b end -local lgen = lanes.gen("*", {}, ret) +local lgen = lanes.gen("*", { name = 'auto' }, ret) for i=1,10000 do local ln = lgen(i) diff --git a/tests/irayo_closure.lua b/tests/irayo_closure.lua index 45189ec..705b85e 100644 --- a/tests/irayo_closure.lua +++ b/tests/irayo_closure.lua @@ -33,5 +33,5 @@ local function useclosurehere() print "using the closure" end -local lane= lanes.gen( "", { globals = { data=1, func=useclosurehere } }, testrun )() +local lane= lanes.gen( "", { name = 'auto', globals = { data=1, func=useclosurehere } }, testrun )() print(lane[1]) diff --git a/tests/irayo_recursive.lua b/tests/irayo_recursive.lua index 0187a15..99522f7 100644 --- a/tests/irayo_recursive.lua +++ b/tests/irayo_recursive.lua @@ -11,7 +11,7 @@ local function recurse() --local lanes = require "lanes" - local lane = lanes.gen( "base,string,lanes_core", { globals = { ["i"]= i + 1 } }, recurse ) () + local lane = lanes.gen( "base,string,lanes_core", { name = 'auto', globals = { ["i"]= i + 1 } }, recurse ) () return lane[1] end diff --git a/tests/keeper.lua b/tests/keeper.lua index 0e93de2..f566927 100644 --- a/tests/keeper.lua +++ b/tests/keeper.lua @@ -160,7 +160,7 @@ if true then end PRINT("lane started") - local h= lanes.gen( "io", lane )() + local h= lanes.gen( "io", { name = 'auto' }, lane )() PRINT("lane joined:", h:join()) PRINT("A.some = " .. A.some ) diff --git a/tests/lanes_as_upvalue.lua b/tests/lanes_as_upvalue.lua index e7fcd3a..beef22e 100644 --- a/tests/lanes_as_upvalue.lua +++ b/tests/lanes_as_upvalue.lua @@ -4,7 +4,7 @@ local function foo() local lanes = lanes -- lanes as upvalue end -local g = lanes.gen( "*", {error_trace_level = "extended"}, foo) +local g = lanes.gen( "*", { name = 'auto', error_trace_level = "extended"}, foo) -- this should raise an error as lanes.timer_lane is a Lane (a non-deep full userdata) local res, err = pcall( g) diff --git a/tests/launchtest.lua b/tests/launchtest.lua index 16db242..57411e1 100644 --- a/tests/launchtest.lua +++ b/tests/launchtest.lua @@ -47,7 +47,7 @@ end local lanes = require "lanes" -local g= lanes.gen( LIBS, function(i) +local g= lanes.gen( LIBS, { name = 'auto' }, function(i) --io.stderr:write( i.."\t" ) return i end ) diff --git a/tests/linda_perf.lua b/tests/linda_perf.lua index 96f26f4..bba1408 100644 --- a/tests/linda_perf.lua +++ b/tests/linda_perf.lua @@ -79,8 +79,8 @@ end -- ################################################################################################# -local lane_eater_gen = lanes.gen( "*", {priority = 3}, eater) -local lane_gobbler_gen = lanes.gen( "*", {priority = 3}, gobbler) +local lane_eater_gen = lanes.gen( "*", { name = 'auto', priority = 3 }, eater) +local lane_gobbler_gen = lanes.gen( "*", { name = 'auto', priority = 3 }, gobbler) -- ################################################################################################# diff --git a/tests/manual_register.lua b/tests/manual_register.lua index 52cc4ed..36a41ad 100644 --- a/tests/manual_register.lua +++ b/tests/manual_register.lua @@ -25,7 +25,7 @@ local f = function() end -local g = lanes.gen( "*", f) +local g = lanes.gen( "*", { name = 'auto' }, f) -- generate a lane, this will transfer f, which pulls GlobalFunc. local h = g() diff --git a/tests/nameof.lua b/tests/nameof.lua index 1abcf3d..fb7332a 100644 --- a/tests/nameof.lua +++ b/tests/nameof.lua @@ -18,7 +18,7 @@ local body = function() end -- start the lane without any library -local h = lanes.gen(nil, body)() +local h = lanes.gen(nil, { name = 'auto' }, body)() SLEEP(0.1) print("Name of lane: ", lanes.nameof(h), "("..h.status..")") assert(h.status == "running") diff --git a/tests/objects.lua b/tests/objects.lua index ed460af..22a4df1 100644 --- a/tests/objects.lua +++ b/tests/objects.lua @@ -8,7 +8,7 @@ local lanes = require "lanes" local linda= lanes.linda() -local start_lane= lanes.gen("io", +local start_lane= lanes.gen("io", { name = 'auto' }, function(obj1 ) assert(obj1.v ) diff --git a/tests/parallel_os_calls.lua b/tests/parallel_os_calls.lua index 8030d4c..55159e8 100644 --- a/tests/parallel_os_calls.lua +++ b/tests/parallel_os_calls.lua @@ -1,15 +1,15 @@ local lanes = require "lanes" print( os.date()) local linda = lanes.linda() -local l1 = lanes.gen("os,base", function() print "start sleeping" linda:receive(3, "null") print("finished_sleeping " .. os.date()) return true end)() -lanes.gen("os,base", function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)() -lanes.gen("os,base", function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)() -lanes.gen("os,base", function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)() +local l1 = lanes.gen("os,base", { name = 'auto' }, function() print "start sleeping" linda:receive(3, "null") print("finished_sleeping " .. os.date()) return true end)() +lanes.gen("os,base", { name = 'auto' }, function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)() +lanes.gen("os,base", { name = 'auto' }, function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)() +lanes.gen("os,base", { name = 'auto' }, function() print "start sleeping" linda:receive(2, "null") print("finished_sleeping " .. os.date()) end)() -- wait, else all lanes will get hard-cancelled at stat shutdown l1:join() --[[ -lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() -lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() -lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() -lanes.gen("os,base", function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() +lanes.gen("os,base", { name = 'auto' }, function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() +lanes.gen("os,base", { name = 'auto' }, function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() +lanes.gen("os,base", { name = 'auto' }, function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() +lanes.gen("os,base", { name = 'auto' }, function() os.execute('sleep 10 && echo finished_sleeping') print( os.date()) end)() ]] diff --git a/tests/perftest.lua b/tests/perftest.lua index 35f522c..fe43cca 100644 --- a/tests/perftest.lua +++ b/tests/perftest.lua @@ -137,10 +137,10 @@ end -- Keep preparation code outside of the performance test -- local f_even= lanes.gen( "base,coroutine,math,table,io", -- "*" = all - { priority= PRIO_EVEN }, sieve_lane ) + { name = 'auto', priority= PRIO_EVEN }, sieve_lane ) local f_odd= lanes.gen( "base,coroutine,math,table,io", -- "*" = all - { priority= PRIO_ODD }, sieve_lane ) + { name = 'auto', priority= PRIO_ODD }, sieve_lane ) io.stderr:write( "*** Counting primes 1.."..M.." "..N.." times ***\n\n" ) diff --git a/tests/pingpong.lua b/tests/pingpong.lua index 3498f49..06c0903 100644 --- a/tests/pingpong.lua +++ b/tests/pingpong.lua @@ -25,8 +25,8 @@ local pingpong = function(name, qr, qs, start) end -- pingpong("L1", '0', '1', true) -local t1, err1 = lanes.gen("*", pingpong)("L1", 'a', 'b', true) -local t2, err2 = lanes.gen("*", pingpong)("L2", 'b', 'a', false) +local t1, err1 = lanes.gen("*", { name = 'auto' }, pingpong)("L1", 'a', 'b', true) +local t2, err2 = lanes.gen("*", { name = 'auto' }, pingpong)("L2", 'b', 'a', false) t1:join() t2:join() diff --git a/tests/protect_allocator.lua b/tests/protect_allocator.lua index 994cb39..e13a57c 100644 --- a/tests/protect_allocator.lua +++ b/tests/protect_allocator.lua @@ -36,7 +36,7 @@ end -- start threads local COUNT = 4 -local gen = lanes.gen( "*", body) +local gen = lanes.gen( "*", { name = 'auto' }, body) for i = 1, COUNT do gen( i) end diff --git a/tests/protectproxy.lua b/tests/protectproxy.lua index ed1bd4f..84887ec 100644 --- a/tests/protectproxy.lua +++ b/tests/protectproxy.lua @@ -5,7 +5,7 @@ local body = function( param) return 1 end -local gen = lanes.gen( "*", body) +local gen = lanes.gen( "*", { name = 'auto' }, body) local mylane = gen( "hello") diff --git a/tests/recursive.lua b/tests/recursive.lua index 716fe60..e294104 100644 --- a/tests/recursive.lua +++ b/tests/recursive.lua @@ -12,7 +12,7 @@ local function func( depth ) end local lanes = require "lanes" - local lane = lanes.gen("*", func)( depth-1 ) + local lane = lanes.gen("*", { name = 'auto' }, func)( depth-1 ) return lane[1] end diff --git a/tests/require.lua b/tests/require.lua index b194af1..f017ddf 100644 --- a/tests/require.lua +++ b/tests/require.lua @@ -19,14 +19,14 @@ local function a_lane() local lanes = require "lanes" assert( lanes and lanes.gen ) - local h= lanes.gen( function() return 42 end ) () + local h= lanes.gen( { name = 'auto' }, function() return 42 end ) () local v= h[1] return v==42 end -- string and table for Lanes itself, package to be able to require in the lane, math for the actual work -local gen= lanes.gen( "math,package,string,table", {package={}},a_lane ) +local gen= lanes.gen( "math,package,string,table", { name = 'auto', package={} },a_lane ) local h= gen() local ret= h[1] diff --git a/tests/rupval.lua b/tests/rupval.lua index 122e0ac..ad5ad9d 100644 --- a/tests/rupval.lua +++ b/tests/rupval.lua @@ -23,7 +23,7 @@ c = function( n) return n <= 0 and z or a( n-1) end -local g = lanes.gen( "base", a) +local g = lanes.gen( "base", { name = 'auto' }, a) local l = g(7) local r = l:join() diff --git a/tests/tobeclosed.lua b/tests/tobeclosed.lua index 7a5e3ae..ef09df3 100644 --- a/tests/tobeclosed.lua +++ b/tests/tobeclosed.lua @@ -86,7 +86,7 @@ do return "success" end - local h = lanes.gen("*", lane_body)() + local h = lanes.gen("*", { name = 'auto' }, lane_body)() do local tobeclosed = h end @@ -118,7 +118,7 @@ do l:set("trip", l_in) do - lanes.gen("*", lane_body)(l_in):join() + lanes.gen("*", { name = 'auto' }, lane_body)(l_in):join() end local _count, _closed = l_in:get("closed") assert(_count == 1 and _closed == 2) diff --git a/tests/track_lanes.lua b/tests/track_lanes.lua index 803fae5..d1670ae 100644 --- a/tests/track_lanes.lua +++ b/tests/track_lanes.lua @@ -43,7 +43,7 @@ end -- sleeper( "main", 1) -- the generator -local g = lanes.gen( "*", sleeper) +local g = lanes.gen( "*", { name = 'auto' }, sleeper) -- start a forever-waiting lane (nil timeout) local forever = g( "forever", 'indefinitely') diff --git a/unit_tests/embedded_tests.cpp b/unit_tests/embedded_tests.cpp index a63383a..9a262d5 100644 --- a/unit_tests/embedded_tests.cpp +++ b/unit_tests/embedded_tests.cpp @@ -234,7 +234,7 @@ TEST_CASE("lanes.embedding.with custom allocator") // lua_setfield(L, -2, "allocator"); // configure {on_state_create = on_state_create_, allocater = "protected"} lua_pcall(L, 1, 0, 0); sprintf_s(script, - "g = lanes.gen('*', {globals = {ID = %d}}, function(id_) lane_threadname('Lane %d.'..id_) logPrint('This is L%d.'..id_) end)" // lane generator + "g = lanes.gen('*', { name = 'auto', globals = {ID = %d} }, function(id_) lane_threadname('Lane %d.'..id_) logPrint('This is L%d.'..id_) end)" // lane generator "for i = 1,%d do _G['a'..i] = g(i) end" // launch a few lanes, handle stored in global a , id_, diff --git a/unit_tests/init_and_shutdown.cpp b/unit_tests/init_and_shutdown.cpp index 7e4c215..9652f2d 100644 --- a/unit_tests/init_and_shutdown.cpp +++ b/unit_tests/init_and_shutdown.cpp @@ -829,6 +829,7 @@ TEST_CASE("lanes.on_state_create setting") // launch a Lane that requires the module. It should succeed because _on_state_create was called and made it possible std::string_view const _script{ " f = lanes.gen('*'," + " { name = 'auto' }," " function()" " local Stuff = require ('Stuff')" " Stuff.DoStuffInC()" diff --git a/unit_tests/lane_tests.cpp b/unit_tests/lane_tests.cpp index bf239ba..0c4feba 100644 --- a/unit_tests/lane_tests.cpp +++ b/unit_tests/lane_tests.cpp @@ -80,7 +80,7 @@ TEST_CASE("lanes.sleep.interactions with timers") " local l = lanes.linda()" " lanes.timer(l, 'gluh', 0.1, 0.1)" // launch a lane that is supposed to sleep forever - " local g = lanes.gen('*', lanes.sleep)" + " local g = lanes.gen('*', { name = 'auto' }, lanes.sleep)" " local h = g('indefinitely')" // sleep 1 second (this uses the timer linda) " lanes.sleep(1)" diff --git a/unit_tests/scripts/coro/basics.lua b/unit_tests/scripts/coro/basics.lua index dc74b7c..cd2f410 100644 --- a/unit_tests/scripts/coro/basics.lua +++ b/unit_tests/scripts/coro/basics.lua @@ -42,7 +42,7 @@ end if true then -- if we start a non-coroutine lane with a yielding function, we should get an error, right? - local fun_g = lanes.gen("*", {name = "auto"}, yielder) + local fun_g = lanes.gen("*", { name = 'auto' }, yielder) local h = fun_g("hello", "world", "!") local err, status, stack = h:join() PRINT(err, status, stack) diff --git a/unit_tests/scripts/lane/cooperative_shutdown.lua b/unit_tests/scripts/lane/cooperative_shutdown.lua index 1204e35..756e33c 100644 --- a/unit_tests/scripts/lane/cooperative_shutdown.lua +++ b/unit_tests/scripts/lane/cooperative_shutdown.lua @@ -31,9 +31,9 @@ end -- the generators -local g1 = lanes.gen("*", lane1) -local g2 = lanes.gen("*", lane2) -local g3 = lanes.gen("*", lane3) +local g1 = lanes.gen("*", { name = 'auto' }, lane1) +local g2 = lanes.gen("*", { name = 'auto' }, lane2) +local g3 = lanes.gen("*", { name = 'auto' }, lane3) -- launch lanes local h1 = g1() diff --git a/unit_tests/scripts/lane/stdlib_naming.lua b/unit_tests/scripts/lane/stdlib_naming.lua index 2e045c3..4884cca 100644 --- a/unit_tests/scripts/lane/stdlib_naming.lua +++ b/unit_tests/scripts/lane/stdlib_naming.lua @@ -63,7 +63,7 @@ local function coro_f(_x) return true end -assert.fails(function() lanes_gen("xxx", {gc_cb = gc_cb}, io_os_f) end) +assert.fails(function() lanes_gen("xxx", { name = 'auto', gc_cb = gc_cb }, io_os_f) end) local stdlib_naming_tests = { diff --git a/unit_tests/scripts/lane/tasking_basic.lua b/unit_tests/scripts/lane/tasking_basic.lua index 99be321..233accf 100644 --- a/unit_tests/scripts/lane/tasking_basic.lua +++ b/unit_tests/scripts/lane/tasking_basic.lua @@ -39,7 +39,7 @@ end PRINT("\n\n", "---=== Tasking (basic) ===---", "\n\n") -local task_launch = lanes_gen("", { globals={hey=true}, gc_cb = gc_cb}, task) +local task_launch = lanes_gen("", { name = 'auto', globals={hey=true}, gc_cb = gc_cb }, task) -- base stdlibs, normal priority -- 'task_launch' is a factory of multithreaded tasks, we can launch several: diff --git a/unit_tests/scripts/lane/tasking_cancelling.lua b/unit_tests/scripts/lane/tasking_cancelling.lua index a4e0fde..85600ab 100644 --- a/unit_tests/scripts/lane/tasking_cancelling.lua +++ b/unit_tests/scripts/lane/tasking_cancelling.lua @@ -36,7 +36,7 @@ end PRINT("\n\n", "---=== Tasking (cancelling) ===---", "\n\n") -local task_launch2 = lanes_gen("", { globals={hey=true}, gc_cb = gc_cb}, task) +local task_launch2 = lanes_gen("", { name = 'auto', globals={hey=true}, gc_cb = gc_cb }, task) local N=999999999 local lane9= task_launch2(1,N,1) -- huuuuuuge... @@ -87,7 +87,7 @@ local wait_send = function() a,b = limited:send("key", "bybye") -- infinite timeout, returns only when lane is cancelled end -local wait_send_lane = lanes.gen("*", wait_send)() +local wait_send_lane = lanes_gen("*", { name = 'auto' }, wait_send)() repeat until wait_send_lane.status == "waiting" print "wait_send_lane is waiting" wait_send_lane:cancel() -- hard cancel, 0 timeout @@ -100,7 +100,7 @@ local wait_receive = function() k, v = limited:receive("dummy") -- infinite timeout, returns only when lane is cancelled end -local wait_receive_lane = lanes.gen("*", wait_receive)() +local wait_receive_lane = lanes_gen("*", { name = 'auto' }, wait_receive)() repeat until wait_receive_lane.status == "waiting" print "wait_receive_lane is waiting" wait_receive_lane:cancel() -- hard cancel, 0 timeout @@ -113,7 +113,7 @@ local wait_receive_batched = function() k, v1, v2 = limited:receive(limited.batched, "dummy", 2) -- infinite timeout, returns only when lane is cancelled end -local wait_receive_batched_lane = lanes.gen("*", wait_receive_batched)() +local wait_receive_batched_lane = lanes_gen("*", { name = 'auto' }, wait_receive_batched)() repeat until wait_receive_batched_lane.status == "waiting" print "wait_receive_batched_lane is waiting" wait_receive_batched_lane:cancel() -- hard cancel, 0 timeout diff --git a/unit_tests/scripts/lane/tasking_comms_criss_cross.lua b/unit_tests/scripts/lane/tasking_comms_criss_cross.lua index db63b8e..497e81d 100644 --- a/unit_tests/scripts/lane/tasking_comms_criss_cross.lua +++ b/unit_tests/scripts/lane/tasking_comms_criss_cross.lua @@ -27,7 +27,7 @@ PRINT("\n\n", "---=== Comms criss cross ===---", "\n\n") -- We make two identical lanes, which are using the same Linda channel. -- -local tc = lanes_gen("io", {gc_cb = gc_cb}, +local tc = lanes_gen("io", { name = 'auto', gc_cb = gc_cb }, function(linda, ch_in, ch_out) lane_threadname("criss cross " .. ch_in .. " -> " .. ch_out) local function STAGE(str) diff --git a/unit_tests/scripts/lane/tasking_communications.lua b/unit_tests/scripts/lane/tasking_communications.lua index b922973..1fd43b0 100644 --- a/unit_tests/scripts/lane/tasking_communications.lua +++ b/unit_tests/scripts/lane/tasking_communications.lua @@ -101,7 +101,7 @@ local function PEEK(...) return linda:get("<-", ...) end local function SEND(...) local _res, _err = linda:send("->", ...) assert(_res == true and _err == nil) end local function RECEIVE() local k,v = linda:receive(1, "<-") return v end -local comms_lane = lanes_gen("io", {gc_cb = gc_cb, name = "auto"}, chunk)(linda) -- prepare & launch +local comms_lane = lanes_gen("io", { name = 'auto', gc_cb = gc_cb }, chunk)(linda) -- prepare & launch SEND(1); WR("main ", "1 sent\n") SEND(2); WR("main ", "2 sent\n") diff --git a/unit_tests/scripts/lane/tasking_error.lua b/unit_tests/scripts/lane/tasking_error.lua index 1e2347f..26f244b 100644 --- a/unit_tests/scripts/lane/tasking_error.lua +++ b/unit_tests/scripts/lane/tasking_error.lua @@ -22,7 +22,7 @@ end PRINT("---=== Tasking (error) ===---", "\n\n") -- a lane that throws immediately the error value it received -local g = lanes_gen("", {gc_cb = gc_cb}, error) +local g = lanes_gen("", { name = 'auto', gc_cb = gc_cb }, error) local errmsg = "ERROR!" if true then diff --git a/unit_tests/scripts/lane/tasking_join_test.lua b/unit_tests/scripts/lane/tasking_join_test.lua index 8f2d4db..2fbce6c 100644 --- a/unit_tests/scripts/lane/tasking_join_test.lua +++ b/unit_tests/scripts/lane/tasking_join_test.lua @@ -34,7 +34,7 @@ PRINT("---=== :join test ===---", "\n\n") -- (unless [1..n] has been read earlier, in which case it would seemingly -- work). -local S= lanes_gen("table", {gc_cb = gc_cb}, +local S= lanes_gen("table", { name = 'auto', gc_cb = gc_cb }, function(arg) lane_threadname "join test lane" set_finalizer(function() end) diff --git a/unit_tests/scripts/lane/tasking_send_receive_code.lua b/unit_tests/scripts/lane/tasking_send_receive_code.lua index 77a4b12..e329a88 100644 --- a/unit_tests/scripts/lane/tasking_send_receive_code.lua +++ b/unit_tests/scripts/lane/tasking_send_receive_code.lua @@ -66,7 +66,7 @@ local function chunk2(linda) end local linda = lanes_linda("auto") -local t2= lanes_gen("debug,package,string,io", {gc_cb = gc_cb}, chunk2)(linda) -- prepare & launch +local t2= lanes_gen("debug,package,string,io", { name = 'auto', gc_cb = gc_cb }, chunk2)(linda) -- prepare & launch linda:send("down", function(linda) linda:send("up", "ready!") end, "ok") -- wait to see if the tiny function gets executed diff --git a/unit_tests/scripts/lane/uncooperative_shutdown.lua b/unit_tests/scripts/lane/uncooperative_shutdown.lua index 56c936b..51e5762 100644 --- a/unit_tests/scripts/lane/uncooperative_shutdown.lua +++ b/unit_tests/scripts/lane/uncooperative_shutdown.lua @@ -12,7 +12,7 @@ local lane = function() end -- the generator -local g1 = lanes.gen("*", {name = "auto"}, lane) +local g1 = lanes.gen("*", { name = 'auto' }, lane) -- launch lane local h1 = g1() -- cgit v1.2.3-55-g6feb