lua-users home
lua-l archive

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

> My app needs to run several threads (4 to begin with). I've 
> thought of assigning them separate Lua states but is this 
> safe? The C code they are controlling is multithreading safe 
> and handles necessary conflicts but still, the Lua machines 
> are supposed to be running "concurrently" in the real sense 
> of the word. And they do need to!

The other thing for you to consider is that lua_lock() is only really
set up as a global Lua access mutex.  That being said, any time there is
a lua_lock() in the code, your multithread code will block.  This was,
actually, a timing issue on Amped, and I worked very hard to make it as
minimal as possible.  I want to reiterate... ANY Lua access (table
writes, for example) will block against the other threads, even though
the accesses have nothing to do with each other.

> P.S. I know of LuaState etc. on Windows but wouldn't like to 
> start using some "fork" of the main project, unless I have to.

All LuaState does for you, in this case, is give you implementations of
lua_lock/unlock() in a way that doesn't cause you to have to #define
them in.  That's all.  You can look at LuaState for Windows
implementation, but other than that, it's nothing you couldn't do on
your own.