[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How to stop yielded threads from being garbage collected
- From: HyperHacker <hyperhacker@...>
- Date: Wed, 23 Nov 2011 16:10:02 -0700
On Wed, Nov 23, 2011 at 15:48, Martin Linklater <mslinklater@gmail.com> wrote:
> Hi - apologies for my ignorance, but I'm quite new to Lua.
>
> I am writing a system where multiple Lua threads are created and updated in
> series on one CPU thread. The lua code can call a Sleep(n) function which
> calls a C function which yields the thread (lua_yield()) and puts it on an
> inactive list. This inactive list is checked 30 times a second and any
> threads that have slept for long enough are then continued by calling
> lua_resume() on them.
>
> This is working fine if I only have a few threads executing, but if I put
> the code under stress and create a lot of lua threads, I get the following
> error when I call lua_resume on a yielded thread:
>
> cannot resume non-suspended coroutine
>
> After doing a bit of digging around on the internet I think this is being
> caused by the thread being garbage collected while it is yielded. Can
> someone please verify if my observed behaviour fits in with this diagnosis,
> and if so, what is the easiest way to stop a yielded thread from being
> garbage collected ?
>
> Thanks for any help you can give.
>
> - Martin
>
It shouldn't be collected as long as there's a reference to it.
--
Sent from my toaster.