title: pthread_sigmask() not work in multithreaded program
body: <p>I'm a newbie in c development. Recently, I noticed a problem when I was learning multi-threaded development, when I set a signal in the main thread of Action and when I try to block the signal action set by the main thread in the child thread, I find that it does not work.</p>
  <p>Here is a brief description of the code</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;signal.h&gt;
  
  void *thread_start(void *_arg) {
    sleep(2);
  
    sigset_t mask;
    sigemptyset(&amp;mask);
    sigaddset(&amp;mask, SIGUSR2);
    pthread_sigmask(SIG_BLOCK, &amp;mask, NULL);
  
    printf(&quot;child-thread executed\n&quot;);
  
    while (true) {
      sleep(1);
    }
  
    return NULL;
  }
  
  void sig_handler(int _sig) {
    printf(&quot;executed\n&quot;);
  }
  
  int main(int argc, char *argv[]) {
    pthread_t t_id;
    int s = pthread_create(&amp;t_id, NULL, thread_start, NULL);
    if (s != 0) {
      char *msg = strerror(s);
      printf(&quot;%s\n&quot;, msg);
    }
  
    printf(&quot;main-thread executed, create [%lu]\n&quot;, t_id);
  
    signal(SIGUSR2, sig_handler);
  
    while (true) {
      sleep(1);
    }
  
    return EXIT_SUCCESS;
  }
  </code></pre>