Boost logo

Boost Users :

From: ajb_at_[hidden]
Date: 2005-07-25 19:46:34


Quoting Christian Henning <chhenning_at_[hidden]>:

> 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?

Andrew Bromage

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at