[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Tables and multithreading
- From: Javier Guerra <javier@...>
- Date: Thu, 16 Mar 2006 07:06:53 -0500
On Thursday 16 March 2006 5:40 am, Framework Studios: Hugo wrote:
> Hi,
>
> If a new thread is created with lua_newthread, can I in that thread create
> a table, add it to another global table (List) and use that other table to
> access the first table in the main thread?
AFAICT, lua_newthread() is only safe out-of-the-box if only one thread is
being executed at any given time. that is, if you don't use OS
multithreading to call each lua thread from different OS threads.
the lua core calls lua_lock()/lua_unlock() at key points, but these are
defined out by default. if you want to make lua threadsafe you have to
define these macros.
the LuaThreads package from Diego Nehab does exactly that.
the downside is that there's a single big lock for each LuaState, not one for
each lua object, so the concurrency is pretty low.
the other way to do concurrency in Lua is to have different and separate
LuaStates, one for each OS thread. then the problem is how to pass data
between them. Thas's the basis of the LuaTask package by Daniel Quintela
--
Javier
Attachment:
pgpsqmAVdEo4f.pgp
Description: PGP signature