.. ot-topic:: sysprog.signal.sync :dependencies: sysprog.signal.intro .. include:: Synchronous Signal Handling =========================== .. topic:: Documentation * `man -s 3 sigwait `__ * `man -s 2 sigwaitinfo `__ * `man -s 2 sigtimedwait `__ .. _sysprog-signals-block: Waiting (Blocking) For Signals ------------------------------ * ``sigwait()`` (and friends) *synchronously wait* for a signal * To make that happen, one must *block* this signal for asynchronous delivery * Good: no :ref:`async-signal-safety ` concerns * |longrightarrow| All fine * Use case: in a multithreaded program, it is probably best to dedicate one thread to signal handling, using ``sigwait()`` or similar. Example: Self-Pipe Trick, Revisited ----------------------------------- .. topic:: Trainer's note * Copy program from :doc:`../async-self-pipe/index`, replace handler and stuff with ``sigwait()`` * Don't block signals initially, seeing ``SIGTERM``'s default disposition (terminate). Only then block it. .. literalinclude:: code/sigwait.cpp :language: c++ :caption: :download:`code/sigwait.cpp`