21 Mar
2005
21 Mar
'05
7:10 p.m.
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:
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.