title: Producer-consumer with sempahores
body: <p>Producer-consumer problem taken from <a href="http://en.wikipedia.org/wiki/Producer-consumer_problem#Using_semaphores" rel="noreferrer">Wikipedia</a>:</p>
  
  <pre><code>semaphore mutex = 1
  semaphore fillCount = 0
  semaphore emptyCount = BUFFER_SIZE
  
  procedure producer() {
      while (true) {
          item = produceItem()
          down(emptyCount)
              down(mutex)
                  putItemIntoBuffer(item)
              up(mutex)
          up(fillCount)
      }
      up(fillCount) //the consumer may not finish before the producer.
  }
  
  procedure consumer() {
      while (true) {
          down(fillCount)
              down(mutex)
                  item = removeItemFromBuffer()
              up(mutex)
          up(emptyCount)
          consumeItem(item)
      }
  }
  </code></pre>
  
  <p>My question - why does the producer have <code>up(fillCount) //the consumer may not finish before the producer</code> after the while loop. When will the program get there and why is it needed?</p>