const N = 100; semaphore mutex = 1; semaphore empty = N; semaphore full = 0; void producer(void) { int item; for (;;) { create(&item); signal(&empty); signal(&mutex); count = count + 1; queue[count - 1] = item; wait(&mutex) wait(&full); } } void consumer(void) { int item; for (;;) { signal(&full); signal(&mutex); item = queue[count - 1]; count = count - 1; wait(&mutex); wait(&empty); consume(&item); } }