Similar questions 2 more →
Synchronization & Concurrency

Answer & solution
Official answer: C
Method
Follow the definitions rather than familiar variable names. Before adding an item, the producer must reserve one writable slot, so it waits on the semaphore initially N. After insertion it creates a readable item, so it signals the semaphore initially 0. The consumer performs the reverse transfer. Waiting for a resource before taking mutex also avoids holding the buffer lock while blocked for another process to make progress. Each successful pair of operations preserves the bounded-buffer accounting.
Solution
Use the definitions supplied, which reverse the usual semaphore names. full starts N and counts producer-writeable slots; empty starts 0 and counts readable items. The producer waits(full) and signals(empty); the consumer waits(empty) and signals(full), each using mutex for buffer access. Thus P=full, Q=empty, R=empty, S=full, C.