lua-users home
lua-l archive

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


On Fri, 2002-06-07 at 14:23, Curt Carpenter wrote:
> As an platform-specific detail, let me just add that on Win32 I have had
> very successful results using a fiber for each Lua thread, and switching
> the fiber instead of using Lua's coroutines. The major advantage is that
> switching a fiber is just a handful of machine instructions. It
> basically just swaps out registers. Using Lua's coroutines requires that
> you unwind the Lua call stack, wind it back up when you continue. The
> only downside is that you need stack space for each thread (but you
> configure that to just what you need). I have run over 1000 fibers/Lua
> threads without any problems. Plus, with fibers you can switch out while
> in the middle of a registered C function. Anyway, it's not a
> general-purpose Lua thing, so it's not for everyone, but I thought some
> people might be interested in that approach if it's a possibility for
> them.

Hmm, just out of curiosity, does anyone know how portable code like that
could be?  I've seen "fibers" used on x86/Linux and Windows, but what
about the other popular processors?  (*Arm, *Sparc, PPC, etc.).  My
stuff being geared mainly for games, portability to things like the
Gameboy Advance or PS2 or other game consoles would be nifty, too.

Thread switching in C functions is a pain the ass (dealing with a
scripting language's task switching, anyways); if the fiber approach is
portable, I may just use that in my own project.  I haven't touched much
on it tho, I assume it would at least require custom assembler for each
architecture?

> 
> -----Original Message-----
> From: Luiz Henrique de Figueiredo [mailto:lhf@tecgraf.puc-rio.br] 
> Sent: Friday, June 07, 2002 9:56 AM
> To: Multiple recipients of list
> Subject: Re: cooperative multitasking
> 
> 
> >Long-running threads with lots of processing would be sprinkled with 
> >yield calls, no?
> 
> Yes, that's why it's called cooperative multitasking.
> 
> >Or I suppose one could use the line-hook, although that would be quite 
> >slow.
> 
> Or the call hook.
> 
> Anyway, cooperative multitasking is provide now in the core of Lua. If
> your platform allows multithreading then you can add that too. An
> example is given in LuaThreads:
> 	http://www.tecgraf.puc-rio.br/~diego/luathreads/
> --lhf