OSMediumSynchronization
Producer-Consumer Problem
đ Problem
Explain the Producer-Consumer problem and how it's solved using semaphores.
đ§ Approach
A producer adds items to a shared buffer, a consumer removes them â but if the buffer is full, the producer must wait, and if it's empty, the consumer must wait. Two counting semaphores solve this: 'empty' (tracks free slots, starts at buffer size) and 'full' (tracks filled slots, starts at 0), plus a mutex to protect the buffer itself during access.