title: About pthread_cond_signal and pthread_cond_wait
body: <p>I have questions about <strong>pthread_cond_signal</strong> and <strong>pthread_cond_wait</strong>. For example, in the code below, According to my understanding, when <strong>inc_count</strong> calls <strong>pthread_cond_signal</strong>, <em>count += 125</em> in <strong>watch_count</strong> can be executed only after <strong>count_mutex</strong> is unlocked in <strong>inc_count</strong>. </p>
  
  <p>The <strong>count_mutex</strong> was unlocked in <strong>watch_count</strong> when <strong>pthread_cond_wait</strong> executed and only gets locked after <strong>pthread_mutex_unlock</strong> in <strong>inc_count</strong> is executed. Am I right?</p>
  
  <pre><code>void *inc_count(void *t) 
  {
      int i;
      long my_id = (long)t;
  
      for (i = 0; i &lt; TCOUNT; i++) 
      {
          pthread_mutex_lock(&amp;count_mutex);
          count++;
  
          if (count == COUNT_LIMIT) 
          {
              pthread_cond_signal(&amp;count_threshold_cv);
          }
  
          pthread_mutex_unlock(&amp;count_mutex);
      }
  
      pthread_exit(NULL);
  }
  
  void *watch_count(void *t) 
  {
      long my_id = (long)t;
  
      pthread_mutex_lock(&amp;count_mutex);
      while (count &lt; COUNT_LIMIT)
      {
          pthread_cond_wait(&amp;count_threshold_cv, &amp;count_mutex);
          count += 125;
      }
  
      pthread_mutex_unlock(&amp;count_mutex);
      pthread_exit(NULL);
  }
  </code></pre>