[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Thread-support in LUA
- From: Bret Mogilefsky <mogul@...>
- Date: Mon, 8 Sep 1997 18:42:37 -0700
Yes, I've done it for my game, but due to legal constraints by my
company, I'm not allowed to fold the changes back into Lua. I did
cooperative multitasking, meaning each thread has to yield in order for
other threads to run and data is shared among the tasks. You're right
in that collecting the globals together per task is the main thing, but
there are some other concerns. In particular, Lua uses recursion for
its call stack... This is fine without multitasking, but as soon as you
add multitasking to the mix things get complex. What happens if, say,
you have functions calling back from C to Lua in one task, so your
frames look like this:
While in another task, it looks like this:
If you yield from that first task to the second task, you are nested way
too deeply for the second task to properly finish or even yield to other
tasks without causing the same problem. The solution is of course to
flatten the Lua call stack, creating an actual stack data structure on
which to push frames without recursing in C. This is actually a lot
more difficult if you do it second (as I discovered to my misery), so
try to get it out of the way before you collect up the global variables.
If you have any questions, send them on and I'll answer them the best I
can without sending out code.
> -----Original Message-----
> From: firstname.lastname@example.org [SMTP:email@example.com]
> Sent: Monday, September 08, 1997 4:07 PM
> To: Bret Mogilefsky
> Subject: Thread-support in LUA
> I'm interested in the possibility of doing some multi-threaded work
> LUA. However, there seem to be many global variables that could make
> this diffucult. I would like to have each "LUA-thread" start out from
> scratch (ie, as LUA normally starts up), and then only execute within
> its own domain.
> I guess I could probably do this as separate processes (ie,
> "fork"-style), but I would prefer to do it with separate threads
> the same process.
> I assume this means I'd have to collect all LUA globals into a
> LUAGlobals structure. I would then have to allocate one such LUAGlobal
> structure for each thread, basically acting as a control block for its
> LUA thread.
> Does this make any sense? Have anybody else attempted something like
> this? Any ideas or suggestions would be most welcome.
> Mike Fahl