[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: green-threads in lua
- From: "Ivan Gagis" <igagis@...>
- Date: Thu, 31 Jul 2008 16:03:53 +0400
lua docs for lua_yield() says that:This function should only be called as the
return _expression_ of a C function, as follows:
return lua_yield (L, nresults);
so, I'm not sure it is possible to use lua_yield() from within the debug hook.
I have not tried this but if it works the it will be a possible way to implement the green threads in lua, thank you for the idea.
But anyway, I do not think that using the debug abilities for normal work is not a very good solution, and not the fastest one.
So, I think that introducing the capability of executing specified number of instructions in the next version of lua will be a good language improvement.
2008/7/31 Patrick Donnelly <email@example.com>
What you are asking for should be done in coroutines; that is, you
On Thu, Jul 31, 2008 at 4:21 AM, Ivan Gagis <firstname.lastname@example.org
> Hi Patrick,
> i'm not sure how can I achieve that with debug hooks. I can set a callback
> to be called when every ,say, 10 instructions are executed, but then I need
> to see how much time they were executing and then execute other lua thread
> (lua_state). How can I do this from within the called callback function? if
> I return from this function the same lua_State will continue execution...
want a function to be resumable and the thread to yield after a
certain number of instructions. You set a debug hook function in C
that will quite simply yield the thread, preferably with a unique
return value you can differentiate from actual return values in your
dispatcher (e.g. a light userdata sentinel). Your dispatcher will then
resume threads constantly until all are finished. For this to work,
you need to somehow handle a thread running other threads using
coroutine.resume (perhaps do nothing if this is acceptable).
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."