I have a GRPC server application I'm developing on macOS. In this application, I need to handle SIGINT and SIGTERM in order to terminate gracefully.
Normally, on Linux, I would use POSIX semaphores, as the functions involved to wait and notify using a POSIX semaphore are async-signal-safe.
However, in macOS, POSIX sempahores are not implemented. I've looked at other possible synchronization primitives to use and I've stumbled upon os_unfair_lock
, which looks nice, but in the documentation it does not state that it is async-signal-safe.
How can I safely have a thread waiting on a condition variable be woken up from a signal handler without resorting to polling an atomic variable, which would be burning CPU?
Thanks
EDIT: The application is in C/C++