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.