I had the same issue long ago with the PUPnP library, hence I wrote “darksidesync” , which signals the main thread using a udp packet (or just by polling).
Not the most elegant solution, but works and is very portable (though I think the Windows build is broken right now)
Van: firstname.lastname@example.org [mailto:email@example.com]
Namens Laurent FAILLIE
Verzonden: Wednesday, 20 April, 2016 11:33
Aan: Lua Mailing List
Onderwerp: Lua callback in another thread
My main thread is used also to declare some Lua callbacks needs to be called when an MQTT data arrived. So I keep a reference to this
function using classical luaL_ref().
Now, my problem : an MQTT data arrives and is handled by another thread, on which I need to created a dedicated Lua_State for this
newly created thread. But how can I retrieve then launch this function in the new lua_state.
Because, for the moment, I'm retrieving the function from the main state, using xmove() it to the new one and this call it ... obviously,
it's crashing as the main state may be busy by other tasks.
In addition, I don't want to block the main thread using mutex as I don't want to have to rely on main thead activities.