[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: Chris Gagnon <cgagnon@...>
- Date: Tue, 6 Oct 2009 17:48:16 -0700
Apologizes for the partial email, what a way to introduce myself ;o)
Lets assume we have a MainState, and a "ThreadTable" in the global table
lua_getfield(MainState, LUA_GLOBALSINDEX, "ThreadTable");
lua_State *thread = lua_newthread(MainState);
int refID = luaL_ref(MainState, -2);
lua_pop(MainState,1);
we now have a new thread ready to go essentially that is anchored in our thread table and we balanced the stack.
Consider:
lua_load(thread, ...);
lua_pcall(thread, 0, 0, 0);
we have kicked of our coroutine now, presumably it can call c functions other lua functions yield itself be resumed and so on.
If say i need to kill off my co routines i can empty out the thread table and those co routines should be GC at some point.
The problem i'm running into is how do I remove my reference/anchor, when the coroutine is simply done.
I have a work around in which I simply wrap all my function calls in another lua function like:
function StartInternal(func, refID, ...)
func(unpack(arg));
-- Unregister coroutine
ThreadTable[refID] = nil;
end
but i would really like to do away with this.
Any suggestions would be greatly appreciated, i feel like there must be some reasonably obvious way to do this I'm overlooking.
I think it's important to note that performance is very important, which is one of the main reasons i want this wrapper gone.
-Chris