[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to stop yielded threads from being garbage collected
- From: Duncan Cross <duncan.cross@...>
- Date: Thu, 24 Nov 2011 10:57:45 +0000
On Wed, Nov 23, 2011 at 11:16 PM, Martin Linklater
<mslinklater@gmail.com> wrote:
> Thanks. So after creating the new thread, stack position -1 contains a thread object. When you say to keep a reference to it do I need to create a Lua table entry which contains that thread object ? Or is there a simpler way ?
>
> Cheers
What I would do is use the registry table, and create an entry where
the key is a light-userdata pointer to the thread. Something like
this:
// thread object is on the top of L's stack
lua_pushlightuserdata(L, lua_topointer(L, -1));
lua_pushvalue(L, -2);
lua_settable(L, LUA_REGISTRYINDEX);
Later, if you want to remove this entry from the registry table and
make the thread garbage-collectable again, push another light userdata
and set its registry table entry to nil.
-Duncan