Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should declare your flag</p> <pre><code> static volatile sig_atomic_t globalFlag = 0; </code></pre> <p>See e.g. <a href="http://www.cplusplus.com/reference/csignal/sig_atomic_t/" rel="nofollow noreferrer">sig_atomic_t</a>, <a href="https://stackoverflow.com/q/8488791/841108">this question</a> and don't forget the <code>volatile</code> qualifier. (It may have been spelled <code>sigatomic_t</code> for C).</p> <p>On Linux (specifically) you could use <a href="http://man7.org/linux/man-pages/man2/signalfd.2.html" rel="nofollow noreferrer">signalfd(2)</a> to get a filedescriptor for the signal, and that fd can be <a href="http://man7.org/linux/man-pages/man2/poll.2.html" rel="nofollow noreferrer">poll(2)</a>-ed by your event loop.</p> <p>Some event loop libraries (<a href="http://libevent.org/" rel="nofollow noreferrer">libevent</a>, <a href="http://software.schmorp.de/pkg/libev.html" rel="nofollow noreferrer">libev</a> ...) know how to handle signals.</p> <p>And there is also the trick of setting up a pipe (see <a href="http://man7.org/linux/man-pages/man2/pipe.2.html" rel="nofollow noreferrer">pipe(2)</a> for more) at initialization, and just <a href="http://man7.org/linux/man-pages/man2/write.2.html" rel="nofollow noreferrer">write(2)</a>-ing some byte on it in the signal handler. The event loop would poll and read that pipe.</p> <p>Read also <a href="http://man7.org/linux/man-pages/man7/signal.7.html" rel="nofollow noreferrer">signal(7)</a> (it explains what are the limited set of functions or syscalls usable inside a signal handler)....</p> <p>BTW, correctness is more important than efficiency. In general, you get few signals (e.g. most programs get a signal once every second at most, not every millisecond).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload