title: Linux : pthread_cond_signal() is not working inside a Signal Handler()
body: <pre><code>Summary
  -----------
  1. In main() am going for pthread_cond_wait().
  2. In signal handler() am waking main() using pthread_cond_signal().
  3. But main() is not coming out from pthread_cond_wait().
  </code></pre>
  
  <p><strong>What is wrong here? help me out.</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;  
  myclass *myObj = NULL;
  </code></pre>
  
  <p>In main I am trying to wait for a signal:</p>
  
  <pre><code>int main()
  {
      myObj = new myclass;    
      /* do something */
      myobj-&gt;gotoWait(); &lt;=== Wait blocked for ever.
      /* do clean up here */
      return 0;
  }
  </code></pre>
  
  <p>Signal handler sending a signal to main thread:</p>
  
  <pre><code>static void signalHandler(int sig, siginfo_t *siginfo, void *context)
  {
      myObj-&gt;wakeFromWait();
  }
  </code></pre>
  
  <p>Actual class implementing the waiting for and sending of signals.</p>
  
  <p>What is wrong here?</p>
  
  <pre><code>myclass::gotoWait()
  {
      pthread_mutex_lock(&amp;mtx);
      pthread_cond_wait(&amp;cnd, &amp;mtx);
      pthread_mutex_unlock(&amp;mtx);
  } 
  myclass::wakeFromWait()
  {
      pthread_mutex_lock(&amp;mtx);
      pthread_cond_signal(&amp;cnd, &amp;mtx);
      pthread_mutex_unlock(&amp;mtx);
  }
  </code></pre>