(no subject)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

(no subject)

Graham Wakefield
Hi all,

I would like to implement a 'thread pool' of Lua states (allocated with lua_newthread); what do I need to do to an existing lua State to clean it up before returning it to the pool?

I figured at least lua_settop(L, 0), but what googling I have done also mentions that I should be careful about exceptions/errors in a state; but no more information could be found.  What do I need to do?


grrr waaa
www.grahamwakefield.net




Reply | Threaded
Open this post in threaded view
|

Re: Pool of lua_newthreads?

Graham Wakefield
(reposted with subject, sorry)

On Apr 2, 2007, at 2:24 AM, Graham Wakefield wrote:

Hi all,

I would like to implement a 'thread pool' of Lua states (allocated with lua_newthread); what do I need to do to an existing lua State to clean it up before returning it to the pool?

I figured at least lua_settop(L, 0), but what googling I have done also mentions that I should be careful about exceptions/errors in a state; but no more information could be found.  What do I need to do?


grrr waaa
www.grahamwakefield.net





grrr waaa
www.grahamwakefield.net




Reply | Threaded
Open this post in threaded view
|

Re:

Graham Wakefield
In reply to this post by Graham Wakefield
Furthermore, if I'm using a lua_State thread pool, can I re-assign the 'parent' state of an existing lua_State?

On Apr 2, 2007, at 2:24 AM, Graham Wakefield wrote:

Hi all,

I would like to implement a 'thread pool' of Lua states (allocated with lua_newthread); what do I need to do to an existing lua State to clean it up before returning it to the pool?

I figured at least lua_settop(L, 0), but what googling I have done also mentions that I should be careful about exceptions/errors in a state; but no more information could be found.  What do I need to do?


grrr waaa
www.grahamwakefield.net





grrr waaa
www.grahamwakefield.net




Reply | Threaded
Open this post in threaded view
|

Re: Pool of lua_newthreads?

Rici Lake-2
In reply to this post by Graham Wakefield
Graham Wakefield wrote:
(reposted with subject, sorry)

On Apr 2, 2007, at 2:24 AM, Graham Wakefield wrote:

Hi all,

I would like to implement a 'thread pool' of Lua states (allocated with lua_newthread); what do I need to do to an existing lua State to clean it up before returning it to the pool?

I figured at least lua_settop(L, 0), but what googling I have done also mentions that I should be careful about exceptions/errors in a state; but no more information could be found. What do I need to do?

If you've executed a lua_resume on the thread, I think it's only safe
to reuse the thread after the thread's function has returned. Otherwise,
you might not properly close open upvalues. You probably should not
attempt to reuse a thread which has thrown an error.

At least, that's the strategy I've used: if the thread has returned
normally, I put it back into the pool; otherwise, I let it get
garbage collected. In almost all cases the thread returns normally,
so it's not worth spending a lot of time worrying about corner
cases. If the thread returns normally, then there should be
nothing on the stack, unless you've asked for return values in
which case you need to pop or xmove them.

You cannot "reparent" a thread.