lua-users home
lua-l archive

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


I think I found a solution based on the
lua_sethook( L, fullstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1 );
concept, in combination with luai_userstatethread/luai_userstatefree (hooks in llimits.h, undocumented except for the source code comment:
"these macros allow user-specific actions when a thread is created/deleted/resumed/yielded."

The "my_exit" function needs to call lua_sethook not only for the main state and the thread-state calling "my_exit", but for all thread states owned by the main lua_state.
I did not find any function to access a list of all thread states in the main state, but the hooks above allow to create and update a list of thread states on my own.

luai_userstatethread/luai_userstatefree need to be defined at compile time, but that's OK in my case.

Nevertheless, I would appreciate an "official" function to exit a Lua state with all threads.



On Wed, Mar 3, 2021 at 10:49 AM Oliver Kroth <oliver.kroth@nec-i.de> wrote:
Yes, your argument is valid
In our case it works as the coroutines run only for a short period
before they return control to main thread.


Oliver

Am 03.03.21 um 10:22 schrieb Viacheslav Usov:
> On Tue, Mar 2, 2021 at 8:12 PM Oliver Kroth <oliver.kroth@nec-i.de> wrote:
>
>>      lua_State *mainthread = G(L)->mainthread;
>>      lua_sethook( mainthread, fullstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1 );
> Does this really work? Hooks are per-coroutine, so if a coroutine
> happens to be running when the above executes, I believe it won't have
> any effect till the main thread resumes, which may never happen.
>
> When solving this problem (in a proprietary project, so, sorry, no
> code) we ended up having to track coroutines and hook all of them.
>
> Note to the original poster: this still does not solve the lua_pcall()
> problem. So this is more of a suggestion that the Lua state should
> terminate rather than a sure fire termination (for other reasons,
> too).
>
> Cheers,
> V.
>