[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Multithreading with Lua 4.0?
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Mon, 3 Jun 2002 06:07:46 -0300
>My app needs to run several threads (4 to begin with). I've thought of
>assigning them separate Lua states but is this safe?
In Lua 4.0, separate Lua states are really separate and the implementation
is multithread-safe. So, yes, you can assign a separate Lua state to each
of your threads and it's safe.
>The FAQ says "The next version will probably bring support for external
>multithreading and coroutines. " Is this so and do I need to run
>single-threaded until then?
This means that Lua 5.0 (like 4.1-work before it) will allow multiple,
but possibily dependent, Lua states, in the sense that states will have their
own run-time information but can share stuff like globals and strings.
For this, the implementation is made multithread-safe but having macros
lua_lock and lua_unlock to isolate critical areas. By default, these macros are
empty because they are system-dependent. Packages like LuaSocket define these
macros to something specific to their multithread scheme (LuaSocket uses POSIX
If your Lua states are completely independent, then you don't need
critical-area control in Lua, and can leave lua_lock and lua_unlock empty.