[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re[2]: LuaJIT + Coco : coroutine issue
- From: Dmitriy Iassenev <iassenev@...>
- Date: Mon, 12 Dec 2005 18:01:39 +0200
Hello Mike,
>> But all is ok only in case when newly created thread is in the lua
>> stack, though I use luaL_ref for referencing thread to prevent it to
>> be garbage collected and to remove it form the lua stack. This scheme
>> works fine for Lua 5.1 alpha, but it doesn work with LuaJIT + Coco.
MP> Well, but what happens? An error or a crash?
access violation on lua_resume call, because lua_state, associated with
the thread, is invalid. using debug memory allocator (which fills freed
data with 'C'), I found, that lua_State, returned by lua_newcthread,
is just freed during garbage collection, i.e. thread is collected
MP> * You get the above error: This must be a logic error somewhere.
MP> You are resuming the wrong coroutine or a coroutine not created
MP> with lua_newcthread. You may never notice this with plain Lua.
it is happened only after 86th update of the thread :). and it seems
to me thread is simply collected. thread function looks like this
while true do
foo()
coroutine.yield()
end
MP> * A crash when running under Windows XP: Please apply this change:
MP> http://lua-users.org/lists/lua-l/2005-12/msg00098.html
I use Windows XP, but I applied your patch before
MP> * Still a crash in a random place: Are you 100% sure you've made a
MP> reference to the coroutine? The incremental garbage collection is
MP> very sensitive to tiny changes and LuaJIT obviously allocates a
MP> few more objects.
code looks like this:
on thread construction
m_state = lua_newcthread(L,0);
VERIFY2 (m_state,"Cannot create new Lua thread");
m_thread_reference = luaL_ref(L,LUA_REGISTRYINDEX);
when thread is finished or we should exit
luaL_unref (L,LUA_REGISTRYINDEX,m_thread_reference);
I can even comment luaL_unref call, but it changes nothing - thread is
collected
MP> I suggest you turn on assertions as described in
MP> jitdoc/luajit_debug.html
no assertion accured during the tests I did
MP> and then check if you get strange errors. This almost always
MP> means a coroutine reference has been lost.
I am sure I have troubles because of the reference, since if I leave
thread in the lua stack all works fine. I used references before in
Lua 5.02 and all worked correct.
--
Best regards,
Dmitriy mailto:iassenev@gsc-game.kiev.ua