title: pthreads wait and signal doubts linux
body: <p>Before pthread wait we lock using a mutex so that some other code might not try to change the condition variable. wait then unlocks the mutex and waits for the signal.</p>
  
  <p>Say, in some other thread i had locked the same mutex and after that, i had used 'signal'. and then unlock thread.
  when signal is done, the waiting thread wakes up and aquires the mutex again.</p>
  
  <pre><code>Thread1                   Thread2
  {                         {
      lock(mutex);               lock(mutex);
      wait(mutex);               signal(mutex);
      unlock(mutex);             unlock(mutex);
  }                          }
  </code></pre>
  
  <p>Say the three thread one statements are enclosed in a while(1) loop. Then assume that thread2 locks the mutex, signals it, and unlocks the mutex. and then doesn't end, but goes to sleep.</p>
  
  <p>So will the value of the condition variable be changed permanently? If three statements of thread one are running in infinite lop, will it never wait and just find that the signal has been given? When wait call returns, does it set the value of the condition variable back to initial value?</p>
  
  <p>If yes, can I use create,destroy or initialize methods on the variables to set the value back? If yes, how? What exactly do these functions do?</p>
  
  <p>Thanks,</p>