[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Plans for version 5.0?
- From: Benoit Germain <bgermain@...>
- Date: Wed, 23 Oct 2002 10:38:05 +0200
Hi,
> Maybe we will have to create a new type in Lua, "threads".
> This in turn
> may change the way threads are created and managed. (This should only
> affect programs that use coroutines and/or multi-threading.)
This reminds me of a little problem I have:
I run several concurrent coroutines, that are essentially of the form
function f ( args )
while true
do
<some stuff that may yield, or not>
coroutine.yield()
end
end
c = coroutine . create ( f , args )
once_per_frame_do = function ( )
call_all_registered_such_coroutines()
end
What I want to achieve is this:
When f() yields somewhere inside <some stuff that may yield, or not> because
of an error that prevents normal processing, I want it to yield in a way
that causes it to resume as if newly created when c() is called again.
How is this achievable, apart from destroying the coroutine and creating a
new one (which is not practical, because those coroutines are referenced by
C++ objects and called from C++, so creating new ones means updating the
reference in the C++ object).
Since this yield may occur in functions called by this block, I suppose that
the stack needs to be unwound down to f()'s level. Is there some easy way of
doing this ?
Oh. maybe I could simply change to:
function g()
<some stuff that may yield, or not>
end
function f ( args )
while true
do
pcall (g,args)
coroutine.yield()
end
end
and have errors signalled by error()...
Regards,
Benoit.