void *producer(void *) void *consumer(void *) { { while(1) while(1) { { // produce item sem_wait(&full_slot); ... pthread_mutex_lock(&m); sem_wait(&empty_slot); item = remove(); pthread_mutex_lock(&m); pthread_mutex_ulock(&m); insert(item); sem_post(&full_slot); pthread_mutex_unlock(&m); // use item sem_post(&full_slot); ... } } } }