Re: sigwait() equivalent
"Ulrich Eckhardt" <eckhardt@satorlaser.com> wrote in message
news:hs4rg4-m4r.ln1@satorlaser.homedns.org...
Hi!
I'm currently terminating an application (console-based) by registering a
control-C handler (via SetConsoleCtrlHandler) and there I'm setting an
event that should signal some other threads to terminate and shut down the
whole application.
What I'm wondering is this now: is there an equivalent to sigwait(), i.e.
instead of simply waiting in the main thread for the event to be set, just
directly wait for a shutdown request? I'm also wondering if there are any
restrictions (like for POSIX signals) on what I can do inside that handler
and if there is something like sigatomic_t.
WaitForSingleObject is probably the most efficient synchronization operation
available in Windows. Furthermore, exiting the app should be an infrequent
occurance, hence not something needing to be optimized. And running the
handler in a separate thread relaxes a lot of the requirements for the
handler, yes you must still synchronize access to shared data, but you can
block on a critical section without deadlock, etc.
I'd also be open to hear different suggestions how to detect and handle a
shutdown request in the application.
Well, if your console is just there to support shutdown, and not displaying
useful data, then a tray icon might be a better place for your app to live.
Uli