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