lua-users home
lua-l archive

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


On Mon, Jul 18, 2011 at 11:43, Doug Currie <doug.currie@gmail.com> wrote:
>
> On Jul 18, 2011, at 9:01 AM, James McKaskill wrote:
>
>> The problem crops up wrt to lua coroutines. Each coroutine has a
>> seperate lua_State*. The callback is hard coded with the coroutine
>> that was active at the time it was created. This is an issue if that
>> thread is not ready (its resumed another thread, is currently yielded,
>> or has been garbage collected).
>
> This is a great reason to use LUA_RIDX_MAINTHREAD for callbacks in Lua 5.2

That only gets you half way there. The main thread won't be gc'ed but
it may not be ready (yielded or resumed another coroutine). The only
method that is guaranteed to work is to create a thread for each
callback, but that seems a bit exuberant. I'm not sure how much
overhead this will entail without some testing. If its too much a
thread pool might be the way to go.

Nevertheless my suggestion for the moment is to be wary when using
callbacks with coroutines.

-- James