Boost logo

Boost Users :

From: Peter Koch Larsen (pkl_at_[hidden])
Date: 2005-07-26 03:49:55


> Hi there, please help me out. Seems I lost my brain over the last weekend.
> ;-))
>
> I'm trying to get myself familiar with the boost::thread lib, by
> reading an article by Bill Kempf published in the C++ magazine in
> 2002.
>
> Here in listing no. 4 he is using two thread (a reader and a writer )
> to access a buffer. In the put() and get() he is using one mutex.

I can't see the article, but I guess I know what's happening.
>
> 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?

The condition.wait() is passed the lock. So inside the condition-wait
code, the mutex of the lock is unlocked. The mutex will stay unlocked for
the duration of the wait-call and then be locked again.

/Peter
>
> I guess my question is more fundamental to threads. But hopefully
> there is someone that can help me out.
>
> Thanks ahead,
> Christian


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net