title: C Confused on how to initialize and implement a pthread mutex and condition variable
body: <p>I'm a little bit confused on how to initialize and implement a pthread mutex and condition variable. The goal of the program is to have producers place a set number of ints in a queue and consumers take the ints out of the queue. I must also be able to define the number of producer and consumer threads that are created. In the starter code, I am give these:</p>
  
  <pre><code>// Locks &amp; Condition Variables
  pthread_mutex_t lock; // Lock shared resources among theads
  pthread_cond_t full;  // Condition indicating queue is full
  pthread_cond_t empty; // Condition indicating queue is empty
  </code></pre>
  
  <p>as shared resources. In the <code>//TODO</code> comment in the main method, one of the steps says to initialize the lock and condition variables. I have a very weak understanding of pthread mutex's and conditions, so would I say:</p>
  
  <pre><code>lock = PTHREAD_MUTEX_INIT;
  full = PTHREAD_MUTEX_INIT;
  empty = PTHREAD_MUTEX_INIT;
  </code></pre>
  
  <p>In the consumer and producer methods, would i just call the lock by saying:</p>
  
  <pre><code>pthread_mutex_lock(&amp;lock);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>pthread_cond_wait(&amp;full, &amp;lock);
  </code></pre>
  
  <p>?</p>
  
  <p>My code is pretty buggy right now, so I want to at least make sure that I'm using the mutex's and conditions correctly before debugging further. Thanks in advance!</p>