[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: "Pre-empting" lua code
- From: John W <jwdevel@...>
- Date: Wed, 9 Mar 2022 13:05:09 -0800
I realize that Lua generally operates in a cooperative multitasking mode.
However, I wonder if it is possible/easy to run a VM like so:
* run some bytecode (say, N instructions)
* check for timeout
* run some more bytecode
* etc.
For some context:
I have a lua VM running a task, and in a bad case, that task could
have an infinite loop.
I would like to fail such a task, after some timeout.
Currently, it just occupies that thread forever, consuming 100% CPU,
and I have to kill my program to fix the situation.
I know in Python there are mechanisms for this, because the core
bytecode interpreter pauses from time to time to check for external
conditions. But does Lua do the same? Or is there a reasonably easy
way to make it do that?
Perhaps it is as simple as adding some checks to luaV_execute? I
imagine I'm not the first to want to do this, but have not found much
in my initial research.
Thanks for any advice
-John