Bounded blocking queue
Implement a first-in, first-out queue with a fixed capacity that producer and consumer threads share. put blocks while the queue is full and take blocks while it is empty, and waiting threads must sleep rather than spin. Use a lock with condition variables (or semaphores), handle spurious wakeups, and explain why your code cannot lose a wakeup or deadlock. Follow-ups may include timeouts on put and take and shutting the queue down cleanly.
No answer yet. Write the first one; the best answer gets endorsed.
