
G'day.
Quoting Christian Henning
If the buffer is empty he uses a condition variable to block the mutex. I don't understand how a writer can then enter the put() and write an item into the buffer? The mutex was just blocked by the reader thread?
I haven't read the article, but I think your misunderstanding might be about how condition variables work. The wait() method on a Boost condition variable is passed a lock on the protecting mutex. It does two things (atomically): suspends the thread and releases the lock. When a waiting thread is woken by the condition being signalled, the opposite happens: the lock is re-acquired and the thread is woken up. So as I understand the code that you're describing, the reason why the writer can enter is that the reader does not hold the lock while it's waiting on the condition variable. Does that help? Cheers, Andrew Bromage