lua-users home
lua-l archive

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


Hi.

I made the multithreaded changes in Lua. I just splited the
main data structure that Lua uses to save the state in two
parts: one global (common to all threads) and one specific to
each thread (stack, basically).

The major change is in the garbage collector: mark&sweep must
traverse all stacks and I decided to stop all threads at this
moment. This synchronization implies that all threads must
check for GC to enable it to occur. It's really a drawback
but I haven't found a better way...

It's implemented using pthreads library and tested in Linux
and Solaris platforms only. I can make the source available.

The following functions were added to the C API:

void lua_openthread(void)
- to be called from a new thread, creates a new LuaThread
  and associates it to the calling thread.

void lua_threadfunction(lua_Object f, lua_Object p)
- starts a new LuaThread by executing function f with
  parameter p.

In Lua the following functions were added:

threadfunction
- behaves like the C function lua_threadfunction.

createmutex
- receives nothing and returns a new mutex.

lockmutex
- receives a mutex and locks it. Returns nothing.

unlockmutex
- receives a mutex an unlocks it. Returns nothing.

destroymutex
- receives a mutex and destroys it. Returns nothing.

Regards,
-- cassino