title: Why do we need a condition check before pthread_cond_wait
body: <p>I am trying to learn basics of pthread_cond_wait. In all the usages, I see either </p>
  
  <pre><code>if(cond is false)
     pthread_cond_wait
  </code></pre>
  
  <p>or</p>
  
  <pre><code>while(cond is false)
     pthread_cond_wait
  </code></pre>
  
  <p>My question is, we want to cond_wait only because condition is false. Then why should i take the pain of explicitly putting an if/while loop. I can understand that without any if/while check before <code>cond_wait</code> we will directly hit that and it wont return at all. Is the condition check solely for solving this purpose or does it have anyother significance. If it for solving an unnecessary condition wait, then putting a condition check and avoiding the cond_wait is similar to polling?? I am using cond_wait like this.</p>
  
  <pre><code>void* proc_add(void *name){
      struct vars *my_data = (struct vars*)name;
      printf("In thread Addition and my id = %d\n",pthread_self());
      while(1){
      pthread_mutex_lock(&amp;mutexattr);
      while(!my_data-&gt;ipt){  // If no input get in
              pthread_cond_wait(&amp;mutexaddr_add,&amp;mutexattr);  // Wait till signalled
              my_data-&gt;opt = my_data-&gt;a + my_data-&gt;b;
              my_data-&gt;ipt=1;
              pthread_cond_signal(&amp;mutexaddr_opt);
      }
      pthread_mutex_unlock(&amp;mutexattr);
      if(my_data-&gt;end)
              pthread_exit((void *)0);
      }
  }
  </code></pre>
  
  <p>The logic is, I am asking the input thread to process the data whenever an input is available and signal the output thread to print it.</p>