[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Anchoring co-routines and properly dropping references to allow GC to clean them up
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Wed, 7 Oct 2009 18:28:42 +0200
2009/10/7 Chris Gagnon <cgagnon@zindagigames.com>:
>
>> Sorry if I misunderstand, but isn't this all you want?
>>
>> lua_getfield(MainState, LUA_GLOBALSINDEX, "ThreadTable");
>> lua_pushnil(MainState);
>> lua_rawseti(MainState, -2, refID);
>> lua_pop(MainState, 1); /* ThreadTable */
>
> I asked the question poorly, the code to release the coroutine isn't the
> problem.
> The placement of that code is, i have multiple entry point back to my co
> routines from different systems that utilize yeild/resume to implement
> functionality.
> Do you need to check the state of the thread after ever lua_resume call? and
> then do code like you suggest?
> Or is there a way to do it more generically then that, I'm leaning towards
> the latter.
>
> Sorry for the confusing question, and thank you for the replies.
You have to check for the return value of lua_resume. If it's anything
other than LUA_YIELD, the coroutine is no longer resumable. Anyway you
need to check that value to make sure you don't call lua_resume on it
anymore, so in that check you can also remove the reference you have
in your ThreadTable (and actually if you only resume coroutines from
that table, that's the only thing you need to do).