lua-users home
lua-l archive

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


> I had a similar problem in the past: killing a running Lua process in a safe way from another OS process. 

Thank you, this works well in a first quick test, when using a state created by luaL_newstate(), not a coroutine state.
I suppose this is what you do with
  lua_State *mainthread = G(L)->mainthread;
Do you have a definition for G()?


On Tue, Mar 2, 2021 at 8:13 PM bel <bel2125@gmail.com> wrote:

> This entire topic is not new. Some applications embedding Lua also
> have a need to terminate a running Lua state, without bringing the
> host down. This is not easy and I am not aware of a really good
> solution to this.

Do you have some links to reference implementations or other reading material?
Even if their solution might not be "perfect", probably the restrictions of these solutions might still be acceptable in my case as well.


> Your problem is lua_pcall()

Understood.
Then I will have a deeper look on that.

> I actually think we should have support for this built into Lua, ...

I fully agree.


On Tue, Mar 2, 2021 at 6:37 PM Viacheslav Usov <via.usov@gmail.com> wrote:
On Tue, Mar 2, 2021 at 1:16 PM bel <bel2125@gmail.com> wrote:

> I never used the word "bug" [...] and that was meant completely neutral ... could have been that I interpret that paragraph in the manual in a different way than it was meant to be, and that's why I post some code.

If you think the word 'bug' is somehow bad, fine, don't use it. It
does not matter. When you think there is a discrepancy between
documentation and observed behavior, you should report minimal repro
steps toward that discrepancy. You actually tried in your first
attempt, and it correctly demonstrated no discrepancy.

Posting your whole research project was unnecessary at that point.

> Wouldn't this have the side effect that the Lua code can no longer use other coroutines?

Possibly, but, as I said, either you do what you want by breaking
Lua's official rules, or you would have to live with some
restrictions.

This entire topic is not new. Some applications embedding Lua also
have a need to terminate a running Lua state, without bringing the
host down. This is not easy and I am not aware of a really good
solution to this. I actually think we should have support for this
built into Lua, but this won't help any current or past versions.

> There is an arbitrarily structured Lua code that may contain other coroutines as well, and at some point this code decides it found what it was looking for, or there is an unrecoverable problem.

Coroutines are not a (major) problem here. Your problem is
lua_pcall(), and we are talking about coroutines because of your
mistaken assumption that coroutines could somehow jump over
lua_pcall() boundaries.

Cheers,
V.