lua-users home
lua-l archive

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


> Depending on what you do next with the Lua state, ...

lua_close

> ... you may not have to terminate each separate thread.

I found out, if I only add hooks to the mainstate and the calling thread state (G(L)->mainthread and L), an intermediate coroutine may still be running:
In the situation "maintread --> start coroutine1 --> start coroutine2 --> my_exit", I have to add hooks to all three coroutines, otherwise coroutine1 will keep running.
(I investigated this with some test code, but that's rather lengthy).
It might not be necessary to add a hook to all Lua coroutines, but only the ones that are involved in the call to "my_exit". But for this I would need an API function like
lua_State * lua_getparentthread(lua_State *L) to recursively determine all involved thread states - but there is no such API function (or: I am unable to find it).
I could store the required information on my own - again using luai_userstatethread - but does it really harm to hook other thread states in the same main state?




On Fri, Mar 5, 2021 at 4:08 PM Oliver Kroth <oliver.kroth@nec-i.de> wrote:
Depending on what you do next with the Lua state, you may not have to
terminate each separate thread.
If you want to close the Lua state (calling lua_close), the garbage
collector will collect and free ALL memory that has been allocated in
this Lua state.

Oliver

Am 05.03.21 um 13:39 schrieb bel:
> 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.