lua-users home
lua-l archive

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



If (as I think) you're talking about OS level pre-emptive threads (and not Lua coroutines), I would strongly suggest looking for a solution s.a. Lanes for this.

I've just finished work on a full revise of it, and will make a fine tuned release early next week. It will give you plenty of tools to get the cancellation done what you're looking for. By the way, would you rather limit the amount of time consumed by the Lua state (a true watchdog) or just the number of Lua instructions?

Early prerelease is available in LuaForge. 'make test' works on Linux and OS X.

-asko


On Sat, 19 Jul 2008 02:33:16 +0400
 "Alexander Gladysh" <agladysh@gmail.com> wrote:
On Thu, Jul 17, 2008 at 12:47 AM, Chip Salzenberg <chip@pobox.com> wrote:
<...>
Mark's very clever approach is to introduce a
"must exit" bit in the Lua state; when that bit is set, the Lua VM starts seeing all instructions as unconditional returns. Within a few microseconds,
you should be *pop* back out of your lua_(p)call.

I apologise for being not quite in context, so my question may be a silly one. I see the expected use case of this feature roughly as
follows (pseudocode):

1. [worker thread] spawn_watchdog_thread(L); lua_pcall(L, <stuff>);
stop_watchdog_thread();
2. [watchdog thread] if (spent_too_much_time()) lua_forcereturn(L, 1);

If forcereturn is triggered, lua_pcall() returns (prematurely) in worker thread, and worker thread execution continues as usual.

The question: How would worker thread know that lua_pcall() returned due to lua_forcereturn() call somewhere (except that it may ask the
watchdog thread)?

I'd expect some LUA_ERRFORCED return code -- anyway, this is an error scenario, since our script presumably was stopped somewhere in the middle. Would I be able to reuse the Lua state after lua_(p)call() was "forcereturned"? If not, then how is such forcereturning different from, say, just calling lua_panic() righ after it was detected that
forcereturn flag was set?

Alexander.