[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Closing a VM (or "Root State") when running threads
- From: "Matthew Harmon" <matt@...>
- Date: Wed, 25 Aug 2004 09:01:50 -0500
Hi Adam:
I'm in a VERY similar situation on a game I'm working on. I create many
"child" states from the main state, and they are all crazily yielding and
resuming throughout execution. Like you, I occasionally have a crash in the
sweep portion of Lua. However, I have not replaced the memory management
functions.
You may be a bit farther along in your debugging efforts than I, but I
thought we may want to stay in contact on this issue in case we can help
each other out. I'm finally about to build a debug version of Lua and try
to trap the error.
I, too, am wondering if there is a problem shutting down a state that is
currently yielded. I can see how that would lock the ability to GC any
remaining data from that thread.
Another thing I do, which is probably bad, is frequently redefine functions.
I'm not sure if that leaves the "old" code available for GC right away or
not.
Matt
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Adam Barnett
Sent: Wednesday, August 25, 2004 3:13 AM
To: lua@bazar2.conectiva.com.br
Subject: Closing a VM (or "Root State") when running threads
Hello,
I have written a script engine that makes use of lua_newthread to generate
and run
several scripts at (approximately) the same time. I have done this using a
VM or "Root State" from which all the threads are created, thereby allowing
sharing of global information across the threads. Due to memory manager
issues, the standard realloc and free commands have been replaced with
functionally identical function calls... but I raise this in case this could
have caused an issue anyway. The threads are controlled by calling
lua_yield and lua_resume from the C code it is embedded in.
The problem is that I want to be able to close the root state in order to
cause all the spawned threads to also end and be GC'ed. This causes a fatal
error (during what seems to be the "Sweep" functions in LUA) when lua_close
is called on the root state. I have tried several possibilities I have
found in the archive such as emptying the root state's stack before calling
lua_close and forcing a GC. I am wondering if the crash is because the
scripts have not finished executing in all cases (i.e. they have been
yielded and have not returned yet).
As such, I am wondering if anyone else has had a similar problem and what
solutions they have found.
Thanks,
Adam Barnett