From 5693bdd8353ae6b623fe5b6210daa72983c220d0 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 11 Jun 2024 14:58:04 +0200 Subject: Adjust lanes.configure() documentation --- tests/appendud.lua | 1 - tests/atomic.lua | 1 - tests/basic.lua | 5 +++-- tests/cyclic.lua | 1 - tests/deadlock.lua | 49 ++++++++++++++++++++++++--------------------- tests/ehynes.lua | 1 - tests/fibonacci.lua | 2 +- tests/hangtest.lua | 1 - tests/irayo_closure.lua | 1 - tests/irayo_recursive.lua | 2 +- tests/launchtest.lua | 1 - tests/objects.lua | 1 - tests/parallel_os_calls.lua | 2 +- tests/pingpong.lua | 2 +- tests/recursive.lua | 8 ++------ 15 files changed, 35 insertions(+), 43 deletions(-) (limited to 'tests') diff --git a/tests/appendud.lua b/tests/appendud.lua index d0efb26..f510c8b 100644 --- a/tests/appendud.lua +++ b/tests/appendud.lua @@ -7,7 +7,6 @@ -- Needs Lanes >= 2.0.3 -- local lanes = require "lanes" -lanes.configure() local _tab = { beginupdate = function (this) print('tab.beginupdate') end; diff --git a/tests/atomic.lua b/tests/atomic.lua index 12bdf02..2de8f52 100644 --- a/tests/atomic.lua +++ b/tests/atomic.lua @@ -5,7 +5,6 @@ -- local lanes = require "lanes" -lanes.configure() local linda= lanes.linda() local key= "$" diff --git a/tests/basic.lua b/tests/basic.lua index cad3764..bdad44c 100644 --- a/tests/basic.lua +++ b/tests/basic.lua @@ -7,7 +7,8 @@ -- - ... -- local config = { with_timers = false, strip_functions = false, internal_allocator = "libc"} -local require_lanes_result_1, require_lanes_result_2 = require "lanes".configure(config) +-- calling configure more than once should work (additional called are ignored) +local require_lanes_result_1, require_lanes_result_2 = require "lanes".configure(config).configure() print("require_lanes_result:", require_lanes_result_1, require_lanes_result_2) local lanes = require_lanes_result_1 @@ -434,7 +435,7 @@ local function chunk2(linda) assert(config.strip_functions and info.short_src=="?" or string.match(info.short_src, "^.*basic.lua$"), "bad info.short_src") -- These vary so let's not be picky (they're there..) -- - assert(info.linedefined == 419, "bad linedefined") -- start of 'chunk2' + assert(info.linedefined == 420, "bad linedefined") -- start of 'chunk2' assert(config.strip_functions and info.currentline==-1 or info.currentline > info.linedefined, "bad currentline") -- line of 'debug.getinfo' assert(info.lastlinedefined > info.currentline, "bad lastlinedefined") -- end of 'chunk2' local k,func= linda:receive("down") diff --git a/tests/cyclic.lua b/tests/cyclic.lua index 553d2a9..fd6d4a0 100644 --- a/tests/cyclic.lua +++ b/tests/cyclic.lua @@ -5,7 +5,6 @@ -- local lanes = require "lanes" -lanes.configure() local table_concat= assert(table.concat) diff --git a/tests/deadlock.lua b/tests/deadlock.lua index c38ca13..bbbda8d 100644 --- a/tests/deadlock.lua +++ b/tests/deadlock.lua @@ -1,8 +1,10 @@ -- this script tests the fix of a bug that could cause the mutex of a keeper state to remain locked -- see https://github.com/LuaLanes/lanes/commit/0cc1c9c9dcea5955f7dab921d9a2fff78c4e1729 -local lanes = require('lanes').configure{with_timers=false} -local linda = lanes.linda "deadlock_linda" +local lanes = require "lanes" + +-- Lua 5.1 compatibility +local table_unpack = table.unpack or unpack local SLEEP = function(...) local k, v = lanes.sleep(...) @@ -14,27 +16,28 @@ print "let's begin" local do_extra_stuff = true if do_extra_stuff then - -- just something to make send() succeed and receive() fail (any C function exposed by some module will do) - local payload = { lanes.require('socket').connect } - - -- lane generator - local g = lanes.gen('*', function() - set_debug_threadname( "deadlock_lane") - -- wrapping inside pcall makes the Lanes module unaware that something went wrong - print( "In lane 1:", table.unpack{ pcall( linda.receive, linda, 'tmp')}) - -- with the bug not fixed, and non-recursive mutexes, we can hang here - print( "In lane 2:", table.unpack{ pcall( linda.receive, linda, 'tmp')}) - -- return something out of the lane - return 33, 55 - end) - - -- send payload twice. succeeds because sending stores a function identification string in the linda's keeper state - linda:send( 'tmp', payload, payload) - -- start the lane - local h = g() - -- wait for lane completion - local err, stack = h:join() - print( 'result of lane execution', err, stack) + local linda = lanes.linda "deadlock_linda" + -- just something to make send() succeed and receive() fail + local payload = { io.flush } + + -- lane generator. don't initialize "io" base library so that it is not known in the lane + local g = lanes.gen('base,table', function() + set_debug_threadname( "deadlock_lane") + -- wrapping inside pcall makes the Lanes module unaware that something went wrong + print( "In lane 1:", table_unpack{ pcall( linda.receive, linda, 'tmp')}) + -- with the bug not fixed, and non-recursive mutexes, we can hang here + print( "In lane 2:", table_unpack{ pcall( linda.receive, linda, 'tmp')}) + -- return something out of the lane + return 33, 55 + end) + + -- send payload twice. succeeds because sending stores a function identification string in the linda's keeper state + linda:send( 'tmp', payload, payload) + -- start the lane + local h = g() + -- wait for lane completion + local err, stack = h:join() + print( 'result of lane execution', err, stack) end -- With the bug not fixed, the linda keeper's mutex is still acquired, diff --git a/tests/ehynes.lua b/tests/ehynes.lua index 9436c7d..cdcd5a5 100644 --- a/tests/ehynes.lua +++ b/tests/ehynes.lua @@ -2,7 +2,6 @@ -- Test from -- local lanes = require "lanes" -lanes.configure() local SLEEP = function(...) local k, v = lanes.sleep(...) diff --git a/tests/fibonacci.lua b/tests/fibonacci.lua index 0ff2f37..51e7137 100644 --- a/tests/fibonacci.lua +++ b/tests/fibonacci.lua @@ -12,7 +12,7 @@ -- Need to say it's 'local' so it can be an upvalue -- -local lanes = require "lanes".configure() +local lanes = require "lanes" local function WR(str) io.stderr:write( str.."\n" ) diff --git a/tests/hangtest.lua b/tests/hangtest.lua index 6a9f7aa..0e44451 100644 --- a/tests/hangtest.lua +++ b/tests/hangtest.lua @@ -3,7 +3,6 @@ -- local lanes = require "lanes" -lanes.configure() local function ret(b) return b diff --git a/tests/irayo_closure.lua b/tests/irayo_closure.lua index 3278d57..45189ec 100644 --- a/tests/irayo_closure.lua +++ b/tests/irayo_closure.lua @@ -11,7 +11,6 @@ e.g. { globals = { data = 1, func = function() useclosurehere() end } }" ]] local lanes = require "lanes" -lanes.configure() local function testrun() assert( print ) diff --git a/tests/irayo_recursive.lua b/tests/irayo_recursive.lua index fe722a3..88f4aab 100644 --- a/tests/irayo_recursive.lua +++ b/tests/irayo_recursive.lua @@ -1,4 +1,4 @@ -local lanes = require "lanes".configure() +local lanes = require "lanes" -- -- Bugs filed by irayo Jul-2008 -- diff --git a/tests/launchtest.lua b/tests/launchtest.lua index f3a6740..16db242 100644 --- a/tests/launchtest.lua +++ b/tests/launchtest.lua @@ -46,7 +46,6 @@ for k,v in pairs( argtable(...) ) do end local lanes = require "lanes" -lanes.configure() local g= lanes.gen( LIBS, function(i) --io.stderr:write( i.."\t" ) diff --git a/tests/objects.lua b/tests/objects.lua index 7668e45..61c280d 100644 --- a/tests/objects.lua +++ b/tests/objects.lua @@ -5,7 +5,6 @@ -- local lanes = require "lanes" -lanes.configure() local linda= lanes.linda() diff --git a/tests/parallel_os_calls.lua b/tests/parallel_os_calls.lua index 7e7de26..8030d4c 100644 --- a/tests/parallel_os_calls.lua +++ b/tests/parallel_os_calls.lua @@ -1,4 +1,4 @@ -local lanes = require "lanes".configure() +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)() diff --git a/tests/pingpong.lua b/tests/pingpong.lua index fdc60a6..3498f49 100644 --- a/tests/pingpong.lua +++ b/tests/pingpong.lua @@ -1,4 +1,4 @@ -local lanes = require 'lanes'.configure() +local lanes = require "lanes" local q = lanes.linda() local pingpong = function(name, qr, qs, start) diff --git a/tests/recursive.lua b/tests/recursive.lua index 139f4c8..97b9c5b 100644 --- a/tests/recursive.lua +++ b/tests/recursive.lua @@ -12,14 +12,10 @@ local function func( depth ) end local lanes = require "lanes" - -- lanes.configure() is available only at the first require() - if lanes.configure then - lanes = lanes.configure{with_timers = false} - end - local lane= lanes.gen("*", func)( depth+1 ) + local lane = lanes.gen("*", func)( depth+1 ) return lane[1] end local v= func(0) assert(v=="done!") -io.stderr:write("\n") +io.stderr:write("TEST OK\n") -- cgit v1.2.3-55-g6feb