Question: This bounded buffer problem requires three semaphores. can it be done with less semaphores? explain? //producer Let's try rephrasing the producer-consumer problem (over a bounded
This bounded buffer problem requires three semaphores. can it be done with less semaphores? explain?
//producer Let's try rephrasing the producer-consumer problem (over a bounded buffer), using semaphores. Need four variables // produce next_produced wait(empty); wait(buf_mutex) // add next_produced to the buffer signal(buf mutex); signal(full); ) while (true); //shared data int n; //also a buffer data structure semaphore buf-mutex = 1; semaphore empty = n; semaphore full -0 //consumer wait(full); wait(buf_mutex); //move from buffer to next consumed signal(buf_mutex); signal(empty); //consume next consumed ) while (true)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
