lua-users home
lua-l archive

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

( Sorry for double reply - I'm an idiot ~,^ )

Looking over the LuaThreads, it appears it makes use of the actual
system threads.

That's serious overkill, unefficient, etc.  When I want to run several
hundred AI threads, creating an OS thread simply won't work.  Plus, it's
not portable to embedded system that have no OS, or an OS without
threading support, etc.

Again, with Lua's co-threads support, it should be very easy (I would
imagine - haven't look at internals in a while) to make a
pre-emptive-ish threading system.  Simply do something akin to forced
yields, add in Lua mutex/semaphore data types, etc.  The main engine
would look at all available threads, and run each for X amount of time
or for X byte-code operations, then return to calling C code.  This way,
an application could launch Lua threads, and then have a
"lua_run_threads" call in the main update/event loop.

It *could* get even fancier by allowing a mixture of pre-emptable
threads and the current cooperative threads, plus a soft-pre-emptive. 
Soft pre-emptive would only pre-emptively switch on "safe" points, such
as when returning from a function call - this way, a given block of code
would be known to never be interrupted (making it easier to code for)
but you don't have to remember to sprinkle yield calls thru-out the

You'd end up with a versatile threading solution that works in any way
needed (pre-emptive for large/complex tasks, cooperative for simple
tasks/generators, etc.), and even allowing both types of threading in
the same application without recompilation or major hacking.

On Tue, 2002-06-18 at 13:12, Eric Tetz wrote:
> --- Sean Middleditch <> wrote:
> > *cough*pre-emptive Lua threads w/ time quotas*cough*
> > 
> > Should I try starting another one of the pre-emptive vs. cooperative
> > threading debates, and throw in the point of killing threads as well?
> > 
> > Really, this feature should be simple to code in with the yield support
> > Lua already has.
> It already has:
> > Long running Lua threads could allow the embedding application to
> > continue running, or simply be killed off.
> Off topic: anyone know how to "kill off a thread" safely in Windows?  There is a KillThread in the
> API, but it definitely does not qualify as "safe".
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup