lua-users home
lua-l archive

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


This is a single vm / multiple thread solution if I'm reading
your description correctly?

What about a multithreaded version of Lua?  Is that on the horizon?

To get around this myself in Windows, I've been experimenting 
around with compiling the Lua src into a cross platform executable 
format such as elf, and then loading it manually into memory
on a per thread basis.  My application requires a single
Lua lib, one process, multiple threads all executing at the same time.

I like the time slice idea, except - you have to call that suspend callback
to give up control.  If a programmer doesn't do this - well, your
program could lock up or fail.  Plus, performance isn't very good 
if you have say, 10 scripts running at the same time.

Regards,
Jim Mathies



-----Original Message-----
From: Thomas Tong [mailto:toes@firestarters.org]
Sent: Thursday, February 10, 2000 8:32 AM
To: Multiple recipients of list
Subject: re: Managing states


---
Is it possible to freeze the execution of a lua program, save its state
and, some time later, restore the saved state and resume execution from
where it stopped?

---

I spent alot of time researching topic this a few weeks back and have
implemented a solution that allows multiple lua programs to run
concurrently while being able to freeze, restart or terminate them at
any point.

The best bang for the buck solution I've found so far is to spawn each
lua invocation in it's own separate thread, and then have a manager
class suspend and wake each lua thread as needed.  That allows you to
neatly avoid many issues with thread syncronization. So far it has
seems to work well and is fairly efficient. I'm using it as the
scripting language for a game title.

What you end up doing is turning a take a bunch of fully multi-tasking
threads and make  them co-operativly multi-task =).

So the manager works like this.

 LuaManager -->
         Runs LuaProgram1 till lua program call waits or time X
         Runs LuaProgram2 ....
         Runs LuaProgram3 ....
         Runs LuaProgram4 ....


The keys is to make each lua program call a "wait" function in the
manager class to get itself suspended after it's done it's update loop.
 Either that or only give the luaProgram a specific timeslice that its
allowed to use.   But that could lead to problems if the luaProgram is
calling C functions that are order dependent.  It's better to make the
luaProgram call wait when it's at a safe point to be suspended.

It's fairly straight forward and doesn't involving messing around with
the LUA src.  

Thomas