title: SIGIO only notifies last thread in threadpool
body: <p>I would like to write a program that, upon <code>SIGIO</code>, signals all of the threads in my threadpool. I have written the following code, but it appears that a socket can only be owned by a single thread at a time, and thus will only notify the last thread in my thread pool of an event. Is there some way I can get my desired behaviour without using a dedicated signal-capturing thread and without having the main process be interrupted?</p>
  <pre><code>void sigFunc(int signo){
      printf(&quot;SIGNAL %li!\n&quot;, gettid());
      return;
  }
  
  static void* poolFunc(){
      printf(&quot;Pool func... %li\n&quot;, gettid());
  
      fcntl(lsocket, F_SETOWN, gettid());
  
      for(;;)
          sleep(1);
  
      return NULL;
  }
  
  int main(int argc, char *argv[]){
      unsigned char val;
      int lsocket;
      pthread_t pool[4];
  
      lsocket = socket(AF_INET, SOCK_STREAM, 0);
  
      // Omitted 15 lines of setting up lsocket, this part is boring
  
      fcntl(lsocket, F_SETFL, fcntl(lsocket, F_GETFL) | O_ASYNC);
  
      signal(SIGIO, sigFunc);
  
      for(val=0; val &lt; 4; val++){
          if(pthread_create(&amp;pool[val], NULL, poolFunc, NULL) != 0){
              printf(&quot;Creation of thread pool failed!\n&quot;);
              exit(1);
          }
  
          if(pthread_detach(pool[val]) != 0){
              printf(&quot;Failed to detach thread in pool...?\n&quot;);
              exit(1);
          }
      }
  
      printf(&quot;Starting main loop...\n&quot;);
  
      for(;;)
          sleep(1);
  }
  </code></pre>
  <p>Output:</p>
  <blockquote>
  <p>$ ./program<br />
  Pool func... 17580<br />
  Pool func... 17582<br />
  Pool func... 17581<br />
  Pool func... 17583<br />
  Pool func... 17584<br />
  Starting main loop...<br />
  SIGNAL 17584!<br />
  SIGNAL 17584!<br />
  SIGNAL 17584!<br />
  SIGNAL 17584!<br />
  SIGNAL 17584!<br />
  ^C</p>
  <p>$ ./program<br />
  Pool func... 17621<br />
  Pool func... 17620<br />
  Pool func... 17623<br />
  Pool func... 17624<br />
  Pool func... 17622<br />
  Starting main loop...<br />
  SIGNAL 17622!<br />
  SIGNAL 17622!<br />
  SIGNAL 17622!<br />
  SIGNAL 17622!<br />
  SIGNAL 17622!<br />
  ^C</p>
  </blockquote>