[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Threads HOWTO?
- From: Mark Hamburg <mhamburg@...>
- Date: Wed, 21 Jul 2004 16:14:56 -0700
You will also need to mutex around uses of the Lua API for each thread.
lua_lock and lua_unlock if properly defined will do this. You will, however,
end up with a lot of mutex overhead.
Mark
on 7/21/04 3:39 PM, Johann Hibschman at jhibschman@yahoo.com wrote:
> Hi all,
>
> Is there any reference on how to use Lua in a heavily-threaded
> application, with some usage of shared state? I'd expect the game
> folks do this all the time, but I couldn't find any good examples.
>
> The best I've been able to come up with is the following: Keep the
> main lua_State object as a singleton, guarded by a mutex. When the
> mutex is acquired, call lua_newthread to get a new co-routine-like
> thread, store the new thread in a global table so it doesn't get GC'd,
> release the mutex on the global thread, then run some code on the new
> thread.
>
> When the new thread is done, re-acquire the global mutex and remove it
> from the don't-GC-me table.
>
> Would this work? This doesn't say anything about ITC, but I can worry
> about that later.
>
> I'm a little worried that the GC would interfere with things, if the
> "run a thread" code were called while the main thread were GCing.
>
> Any hints or pointers?
>
> Thanks,
>
> Johann
>