Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Timer stops fiber hub #29

Open
AlexKordic opened this Issue · 4 comments

2 participants

AlexKordic alfred-dev
AlexKordic

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
alfred-dev

Is this still relevant? I dont get any hangs and I get the expected output.

AlexKordic

Can't really help, I have forgotten all the details about this issue.

AlexKordic

Can't really help, I have forgotten all the details about this issue.

AlexKordic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.