You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to be able to stop the environment when the application receives a SIGINT/SIGQUIT and send a message to a component to reload the configuration when SIGHUP is received.
Doing this seems to work:
auto stop_app= [](intsignal) ->void {
main_env->stop();
};
...
std::signal(SIGTERM, stop_app);
However, reading the code in environment_t::stop() I suspect it is not safe to call from the context of an async signal. The same goes for sending a message to a mbox/mchain, AFAIU there is the possibility of a deadlock if the signal just happens to be delivered while the message box mutex is being held.
How can OS signals be handled safely. I can only think of a few options:
Have a dedicated thread to handle signals.
Make a custom implementation of mchain that uses a self-pipe.
Periodically poll signals through a signalfd.
Wait on a signalfd from another thread and send a message though a mchain.
Make a custom timer thread implementation that replaces the condition variable by an eventfd or self-pipe, so that it can simultaneously wait on other FDs or receive data from a signal handler.
The text was updated successfully, but these errors were encountered:
Some of approaches you mentioned should also work and don't seem to be complex in implementation, for example:
Periodically poll signals through a signalfd.
Wait on a signalfd from another thread and send a message though a mchain.
But this case:
Make a custom timer thread implementation that replaces the condition variable by an eventfd or self-pipe, so that it can simultaneously wait on other FDs or receive data from a signal handler.
seems to be overkill in implementation complexity.
I need to be able to stop the environment when the application receives a SIGINT/SIGQUIT and send a message to a component to reload the configuration when SIGHUP is received.
Doing this seems to work:
However, reading the code in environment_t::stop() I suspect it is not safe to call from the context of an async signal. The same goes for sending a message to a mbox/mchain, AFAIU there is the possibility of a deadlock if the signal just happens to be delivered while the message box mutex is being held.
How can OS signals be handled safely. I can only think of a few options:
The text was updated successfully, but these errors were encountered: