Back to the 2023 paper

Module 3: Inter-process Communication

20236m

State producer-consumer problem. Give a solution to this problem using semaphore. Justify that your solution guarantees mutual exclusion.

Worked SolutionAI Assisted

Producer-Consumer with Semaphore

Shared buffer size N, sem empty=N, full=0, mutex=1.
Producer: wait(empty), wait(mutex), produce to buffer, signal(mutex), signal(full)
Consumer: wait(full), wait(mutex), consume, signal(mutex), signal(empty)
Guarantees mutual exclusion via mutex, and counting sems prevent overflow/underflow, bounded waiting.

Similar questions

Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.