title: How to wake up a pthread which is sleeping in recvmsg()?
body: <p>I have a little Unix daemon which uses pthreads. One thread runs in a loop, reading network packets using <code>recvmsg</code>. When the daemon receives a signal, a flag is set telling all the threads to break out of their loops and exit. However, the "listening" thread never checks the flag until the next packet arrives and <code>recvmsg</code> returns, which can take some time.</p>
  
  <p>Delivering a <code>SIGINT</code> to the "listening" thread using <code>pthread_kill</code> makes it break out of <code>recvmsg</code>, but it also invokes the signal handler which processes breaks sent by pressing Ctrl+C at the console. That is unwanted. Another way to force <code>recvmsg</code> to return early is to close the socket which it is listening on, but I think there must be a better way. Do you know what it is?</p>
  
  <p>This daemon is used on Linux only, if it makes a difference.</p>