lua-users home
lua-l archive

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

> Ah, I see.  Maybe in another year or two then when no console would
show it's face without 128/256MB of RAM... ~,^

Doubtful. Anyway, I forgot to say I am only using them on the server
(yes, for a game), not on the client.

> Hmm, in what I've worked on, a thread switch in the script engine
could be as fast as changing a pointer

The limitation is when you have a call into a registered function, and
you want it to block and return control to your "normal" non-Lua C code.
At that point you have a call stack that looks something like this:


So with a fiber, all that stays as is, you switch to your C code, and
switch back when you like, and when you do that stack is still exactly
as it was. With a coroutine, if you want to yield
_but_not_to_another_Lua_thread_, you have to unwind all that, and wind
it back up when you resume it, and you have to write your registered
functions such that they return, even when blocked. With fibers you can
block in a synchronous way, thus doing work in the function after being
unblocked, but before returning to Lua. Again, I'm sure it's not for
everyone, but it has been a useful approach for me, so maybe it is for
someone else too.