title: Implementing timer using select
body: <p>I am planning to write a small timer library in C using <code>timerfd_create</code>.</p>
  
  <p>The basic user of this library will have two threads</p>
  
  <ul>
  <li>application thread</li>
  <li>Timer thread </li>
  </ul>
  
  <p>There will be a queue between these two threads so that whenever the application wants to start a timer, it will push a message into the queue which the timer thread will then read and create an FD for it and put it in <code>select</code>.</p>
  
  <p>The problem with the above approach is that the timer thread being a single thread would be blocked in the <code>select</code> system call and would not know if a message has been posted in his receive queue to start a timer. </p>
  
  <p>One way around this is to let the select timeout every "tick" and then check for messages in the queue. Is their a better way to do this?
  I was also thinking of raising an Interrupt every time the application puts a message in the <code>select</code> queue to interrupt the <code>select</code>. Does that work well with Multi-threaded applications?</p>
  
  <p>Platform : Unix</p>