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

AI LearningWeb Platform

Coursify — Personal AI Course Generator

Struggling with a difficult subject or concept? Turn any engineering topic into a structured course with interactive lessons, quizzes, and research-backed explanations.