Question: void * producer ( void * arg ) { / / core of producer for ( i = 0 ; i < num; i +

void *producer(void *arg){//core of producer
for (i =0; i < num; i++){
sem_wait(&empty);
sem_wait(&mutex);
put(i);
sem_post(&mutex);
sem_post(&full);
}
}
void *consumer(void *arg){// core of consumer
while (!done){
sem_wait(&full);
sem_wait(&mutex);
int tmp = get(i);
sem_post(&mutex);
sem_post(&empty);
// do something with tmp ...
}
}
using this classic semaphore version of the producer/consume, select whether the statement is true or false. The semaphore full must be initialized to 1.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!