Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You might like to set up this a bit differently:</p> <p>1 <strong>Before spawning any thread</strong> use <code>pthread_sigmask()</code> to make the app ignore all signals. This behaviour will then be inheritied by any thread created afterwards and will make them not eat away any signals, as only the main thread is to handle them (see step 2 below).</p> <p>2 <strong>After having created all threads</strong> use <code>pthread_sigmask()</code>again to make the main thread receive <code>SIGALRM</code> and use <code>sigaction()</code> (instead of <code>signal()</code>; also see my comment on the OP) to set up the signal handler for <code>SIGALRM</code>.</p> <p>3 Declare a <strong>flag for each thread</strong>. Currently a thread resetting the flag might do this before another thread had started.</p> <hr> <p>If the main thread does not have to do anthing alse (or you do not mind spawning another thread): Alternativly to installing a signal handler using <code>sigaction()</code> (as described in step 2 above) you could use something like <code>do { int sig = sigwaitinfo(...); ... } while (1);</code> to pull the signals received from the the queue and set the flags used to trigger the start of the queries. </p> <hr> <p><strong>Update</strong>:</p> <p>Example on how to use <code>pthread_sigmask()</code> to block <strong>all</strong> signals for the calling thread:</p> <pre><code>sigset_t sigset; sigfillset(&amp;sigset); if (pthread_sigmask( SIG_BLOCK, &amp;sigset, NULL)) { perror("pthread_sigmask"); } </code></pre> <p>Example on how to use <code>pthread_sigmask()</code> to unblock <code>SIGALRM</code> for the calling thread:</p> <pre><code>sigset_t sigset; sigemptyset(&amp;sigset); sigaddset(&amp;sigset, SIGALRM); if (pthread_sigmask( SIG_UNBLOCK, &amp;sigset, NULL)) { perror("pthread_sigmask"); } </code></pre> <p>For more details on <code>pthread_sigmask()</code> please see <code>man pthread_sigmask()</code>.</p>
 

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