title: Producer-consumer with conditional variable
body: <p>I'm looking at the standard solution for the consumer producer problem using conditional variables (this one from the Stanford U website)</p>
  
  <pre><code>char buffer[SIZE];
  int count = 0, head = 0, tail = 0;
  struct lock l;
  struct condition notEmpty;
  struct condition notFull;
  
  lock_init(&amp;l);
  condition_init(&amp;notEmpty);
  condition_init(&amp;notFull);
  
  void put(char c) {
      lock_acquire(&amp;l);
      while (count == SIZE) {
          condition_wait(&amp;notFull, &amp;l);
      }
      count++;
      buffer[head] = c;
      head++;
      if (head == SIZE) {
          head = 0;
      }
      condition_signal(&amp;notEmpty, &amp;l);
      lock_release(&amp;l);
  }
  
  char get() {
      char c;
      lock_acquire(&amp;l);
      while (count == 0) {
          condition_wait(&amp;notEmpty, &amp;l);
      }
      count--;
      c = buffer[tail];
      tail++;
      if (tail == SIZE) {
          tail = 0;
      }
      condition_signal(&amp;notFull, &amp;l);
      lock_release(&amp;l);
      return c;
  }
  </code></pre>
  
  <p>My question is why would I need two conditions? Why it's not gonna work with just one? When the buffer is full it will signal the consumer and when the buffer is empty it will signal the producer, using the same signal.</p>