lua-users home
lua-l archive

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


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