|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-21 14:10:19
Howard Hinnant wrote:
> On Mar 19, 2005, at 1:29 PM, Leon Mergen wrote:
[...]
>> Now, since it is very well possible a thread handles at least 1,000
>> jobs before statistics data is actually read from, I want it to hold a
>> mutex lock to the data at all time. [...]
>
> This sounds like a good application for condition variables:
>
> http://www.boost.org/doc/html/condition.html
Yes. Mutexes should never be used to block a thread until some event occurs.
Their purpose is to serialize access to a shared resource, and you should
strive to make the section between the lock and the unlock as short as
possible. The design of scoped_lock tries to point you in that direction.
Condition variables are the proper primitive to make a thread wait for an
event.
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