luv
luv copied to clipboard
Timer stops fiber hub
I am using timers to implement thread.yield (or sleep(0)). Luv's fiber hub hangs in this case.
Test code:
local luv = require('luv')
local spawn = function (func, ...)
local arguments = {...}
local fiber = luv.fiber.create(function()
local status_code, err_message = pcall(func, unpack(arguments))
if(status_code == true) then
print("fiber completed successfully")
return err_message
else
print("fiber error")
print("Exception in fiber: " .. tostring(err_message))
return nil
end
end)
fiber:ready()
return fiber
end
local sleep = function (miliseconds)
local sleep_timer = luv.timer.create()
sleep_timer:start(miliseconds, miliseconds)
sleep_timer:wait()
sleep_timer:stop()
end
function fiber_yield()
local simple_task = function (param)
for i=1,10 do
print("task:", tostring(param))
sleep(0)
end
end
local worker1 = spawn(simple_task, 1)
local worker2 = spawn(simple_task, 2)
-- worker1:join()
worker2:join()
end
fiber_yield()
Test output:
luv_fiber.c: 42: luvL_fiber_create: spawn fiber as child of: 0013A7E8
luv_fiber.c: 15: luvL_fiber_ready: insert fiber 0013F1B8 into queue of 0013A7E8
luv_thread.c: 69: luvL_thread_enqueue: need async
luv_fiber.c: 42: luvL_fiber_create: spawn fiber as child of: 0013A7E8
luv_fiber.c: 15: luvL_fiber_ready: insert fiber 0013F720 into queue of 0013A7E8
luv_fiber.c: 103: luv_fiber_join: joining fiber[0013F720], from [0013A7E8]
luv_fiber.c: 112: luv_fiber_join: calling luvL_state_suspend on 0013A7E8
luv_thread.c: 26: luvL_thread_suspend: loop top
luv_thread.c: 94: luvL_thread_once: [0013A7E8] rouse fiber: 0013F1B8
luv_thread.c: 110: luvL_thread_once: [0013A7E8] calling lua_resume on: 0013F1B8
task: 1
luv_cond.c: 9: luvL_cond_wait: SUSPEND state 0013F1B8
luv_fiber.c: 25: luvL_fiber_suspend: FIBER SUSPEND - READY? 2
luv_fiber.c: 31: luvL_fiber_suspend: about to yield...
luv_thread.c: 112: luvL_thread_once: resume returned
luv_thread.c: 117: luvL_thread_once: [0013A7E8] seen LUA_YIELD
luv_thread.c: 94: luvL_thread_once: [0013A7E8] rouse fiber: 0013F720
luv_thread.c: 110: luvL_thread_once: [0013A7E8] calling lua_resume on: 0013F720
task: 2
luv_cond.c: 9: luvL_cond_wait: SUSPEND state 0013F720
luv_fiber.c: 25: luvL_fiber_suspend: FIBER SUSPEND - READY? 2
luv_fiber.c: 31: luvL_fiber_suspend: about to yield...
luv_thread.c: 112: luvL_thread_once: resume returned
luv_thread.c: 117: luvL_thread_once: [0013A7E8] seen LUA_YIELD
luv_timer.c: 9: _timer_cb: rouse 0013F1B8
luv_cond.c: 33: luvL_cond_broadcast: READY state 0013F1B8
luv_fiber.c: 15: luvL_fiber_ready: insert fiber 0013F1B8 into queue of 0013A7E8
luv_thread.c: 69: luvL_thread_enqueue: need async
luv_timer.c: 9: _timer_cb: rouse 0013F720
luv_cond.c: 33: luvL_cond_broadcast: READY state 0013F720
luv_fiber.c: 15: luvL_fiber_ready: insert fiber 0013F720 into queue of 0013A7E8
luv_thread.c: 29: luvL_thread_suspend: uv_run_once returned, active: 1
luv_thread.c: 26: luvL_thread_suspend: loop top
luv_thread.c: 94: luvL_thread_once: [0013A7E8] rouse fiber: 0013F1B8
luv_thread.c: 110: luvL_thread_once: [0013A7E8] calling lua_resume on: 0013F1B8
task: 1
luv_cond.c: 9: luvL_cond_wait: SUSPEND state 0013F1B8
luv_fiber.c: 25: luvL_fiber_suspend: FIBER SUSPEND - READY? 2
luv_fiber.c: 31: luvL_fiber_suspend: about to yield...
luv_thread.c: 112: luvL_thread_once: resume returned
luv_thread.c: 117: luvL_thread_once: [0013A7E8] seen LUA_YIELD
luv_thread.c: 94: luvL_thread_once: [0013A7E8] rouse fiber: 0013F720
luv_thread.c: 110: luvL_thread_once: [0013A7E8] calling lua_resume on: 0013F720
task: 2
luv_cond.c: 9: luvL_cond_wait: SUSPEND state 0013F720
luv_fiber.c: 25: luvL_fiber_suspend: FIBER SUSPEND - READY? 2
luv_fiber.c: 31: luvL_fiber_suspend: about to yield...
luv_thread.c: 112: luvL_thread_once: resume returned
luv_thread.c: 117: luvL_thread_once: [0013A7E8] seen LUA_YIELD
luv_timer.c: 9: _timer_cb: rouse 0013F1B8
luv_cond.c: 33: luvL_cond_broadcast: READY state 0013F1B8
luv_fiber.c: 15: luvL_fiber_ready: insert fiber 0013F1B8 into queue of 0013A7E8
luv_thread.c: 69: luvL_thread_enqueue: need async
luv_timer.c: 9: _timer_cb: rouse 0013F720
luv_cond.c: 33: luvL_cond_broadcast: READY state 0013F720
luv_fiber.c: 15: luvL_fiber_ready: insert fiber 0013F720 into queue of 0013A7E8
luv_thread.c: 167: _async_cb: interrupt loop
Expected output, without log noise, is:
task: 1
task: 2
task: 1
task: 2
task: 1
task: 2
task: 1
task: 2
task: 1
task: 2
task: 1
task: 2
task: 1
task: 2
task: 1
task: 2
task: 1
task: 2
task: 1
task: 2
fiber completed successfully
fiber completed successfully
Is this still relevant? I dont get any hangs and I get the expected output.
Can't really help, I have forgotten all the details about this issue.
Can't really help, I have forgotten all the details about this issue.
Can't really help, I have forgotten all the details about this issue.
On Tue, May 6, 2014 at 12:10 PM, alfred-dev [email protected]:
Is this still relevant? I dont get any hangs and I get the expected output.
— Reply to this email directly or view it on GitHubhttps://github.com/richardhundt/luv/issues/29#issuecomment-42285386 .