Question: Using the picture below, will there be any deadlock if the order of the downs were switched, for producer or for consumers individually as well
Using the picture below, will there be any deadlock if the order of the downs were switched, for producer or for consumers individually as well as together (so 3 combinations)? Explain. Thanks!
Producer-consumer Problem using Semaphores Here, the semaphores solve the lost-wakeup problem: semaphore mutex 1; /* binary semaphore providing mutual exclusion */ semaphore empty-N; counting semaphore, counts empty buffer slots */ semaphore full-0: counting semaphore, counts full buffer slots */ void producer(void) void consumer(void) while(TRUE) while(TRUE) int item = produce-item(); down(&empty); down(&mutex); // Enter CR insert_item(item); lput in buffer up(&mutex); I/ Leave CR up(&full) down(&full); down(&mutex); // Enter CR int item-remove-item //remove item from buffer up(&mutex); // Leave CR up(&empty); consume item(item); // do something with it Producer-consumer Problem using Semaphores Here, the semaphores solve the lost-wakeup problem: semaphore mutex 1; /* binary semaphore providing mutual exclusion */ semaphore empty-N; counting semaphore, counts empty buffer slots */ semaphore full-0: counting semaphore, counts full buffer slots */ void producer(void) void consumer(void) while(TRUE) while(TRUE) int item = produce-item(); down(&empty); down(&mutex); // Enter CR insert_item(item); lput in buffer up(&mutex); I/ Leave CR up(&full) down(&full); down(&mutex); // Enter CR int item-remove-item //remove item from buffer up(&mutex); // Leave CR up(&empty); consume item(item); // do something with it
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
