In the bounded-buffer producer-consumer problem with n slots using semaphores mutex, empty and full, what are their initial values?
Correct answer D. mutex = 1, empty = n, full = 0
mutex guards the buffer, so it starts at 1 to let one process in. empty counts free slots and starts at n because the buffer is empty, and full counts filled slots and starts at 0. The producer waits on empty before inserting and signals full afterwards; the consumer does the reverse. Swapping the initial values of empty and full would make the consumer read slots that hold nothing.
Answer checked How we write and check questions
Discussion