Q20
MCQMarks unknownThe following solution to the single producer single consumer problem uses semaphores for synchronization. #define BUFFSIZE 100 buffer buf[BUFFSIZE]; int first = last = 0; semaphore b_full = 0; semaphore b_empty = BUFFSIZE void producer() { while(1) { produce an item; p1:.................; put the item into buff (first); first = (first+1)%BUFFSIZE; p2: ...............; } } void consumer() { while(1) { c1:............ take the item from buf[last]; last = (last+1)%BUFFSIZE; c2:............; consume the item; } }
Sign in to save attempts.
Loading…