lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi.

I am having some trouble with the lua_State threads and the garbage
collection. What I am attempting to do is this:

I create a lua_State with lua_newthread, push the function call on the
new thread's stack, and call it. This thread may or may not yield
through a sleep function. If it yields, another part of the
application will resume the lua_State at the appropriate time.

This leaves me with a problem regarding the garbage collection, since
the thread is on the global state's stack when created. I cannot pop
it after creating it because it will ruin for the lua_resume on the
thread after a potential yield.

I've worked out that I can find out whether the thread is suspended or
not accessing (lua_State)myThread->ci->state & CI_YIELD, and I can use
that to determine when to queue the thread for garbage collection. The
only issue is that I do not know how to remove the references from
G(myThread) to myThread.

Any suggestions?

- Petter Rønningen