title: What is the best solution to pause and resume pthreads?
body: <p>I've found the following topic (<a href="https://stackoverflow.com/questions/3140867/suspend-pthreads-without-using-condition">here</a>) about pthreads but there are many good solutions.</p>
  
  <p>I wanted to know if the following piece of code is valid and if so, why the same lock is used to call pthread_cond_wait as well as access it and then unlocked right away:</p>
  
  <pre><code>void suspendMe()
  {
      pthread_mutex_lock(&amp;m_SuspendMutex);
      pthread_cond_wait(&amp;m_ResumeCond, &amp;m_SuspendMutex);
      pthread_mutex_unlock(&amp;m_SuspendMutex);
  }
  </code></pre>
  
  <p>Would it not be better to use 2 separate mutexes here, or is this the correct way to suspend a pthread??</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Awesome replies, thanks all.
  Just one more related question. Since I want to resume a thread separately in another function, would this be more proper in resuming it?</p>
  
  <pre><code>void suspendMe()
  {
      pthread_mutex_lock(&amp;m_SuspendMutex);
      pthread_cond_wait(&amp;m_ResumeCond, &amp;m_SuspendMutex);
  }
  void resumeMe()
  {
      pthread_cond_signal(&amp;m_ResumeCond);
      pthread_mutex_unlock(&amp;m_SuspendMutex);
  }
  </code></pre>
  
  <p>Thanks again everyone!! :~)</p>