title: pthread_cond_timedwait not returning after specified timeout
body: <p>In the following code <code>execute_on_thread()</code> will keep on printing ".",
  while the <code>main</code> function waits for a condition to be signaled from <code>execute_on_thread</code> using <code>pthread_cond_timedwait</code>. However, it is not timing out after the specified 20 second timeout, it just keeps printing ".", nothing else is happening.</p>
  
  <pre><code>#include &lt;errno.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;time.h&gt;
  #include &lt;unistd.h&gt;
  
  #define SHOW_TECH_CMD_MAX_EXEC_TIME       5 //in secs 
  pthread_mutex_t waitMutex = PTHREAD_MUTEX_INITIALIZER;
  pthread_cond_t waitCond = PTHREAD_COND_INITIALIZER;
  
  void *execute_on_thread();
  void *execute_on_thread()
  {
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_mutex_lock( &amp;waitMutex );
    while(1)
    {
      printf(".");
    }
    pthread_cond_signal( &amp;waitCond );
    pthread_mutex_unlock( &amp;waitMutex );
    return (void *) 0;
  
  }
  int main( )
  {
    pthread_t tid;
    struct timespec   ts;
    int error;
    clock_gettime(CLOCK_REALTIME, &amp;ts);
    ts.tv_sec += 20; 
    pthread_create(&amp;tid,NULL,execute_on_thread,NULL);
    pthread_mutex_lock(&amp;waitMutex);
    error = pthread_cond_timedwait(&amp;waitCond, &amp;waitMutex,&amp;ts);
    pthread_mutex_unlock(&amp;waitMutex);
    printf("come here 1\n");
    if(error == ETIMEDOUT)
    {
      printf("come here 2\n");
      error = pthread_cancel(tid);
      if(error != 0)
      {
         printf("come here 3\n");
      }
    }
  }
  </code></pre>