From: Peter Dimov (pdimov_at_[hidden])
Date: 2008-05-25 14:24:08
> I'm doing a thesis related to C++0x and threading. Peter Dimov suggested I
> could try and implement an event-like waiting primitive, similar to
> WaitForMultipleObjects. If we had such a primitive, we might get better
> to solve this problem. I think part of the reason this is so tricky is
> because condition_variable's aren't meant to be used for multiple waiting.
> Maybe Dimov or somebody else has sketches of such an interface.
I believe that futures only need the basic "manual reset event" in Windows
event(); // post: !is_set_
void set(); // post: is_set_
void reset(); // post: !is_set_
void wait(); // block until is_set_
The advantage of this primitive is that it maps to Windows directly. The
disadvantage is that it's not robust when reset() is used because this
introduces a race. This is not a problem for futures since they are one-shot
and their underlying ready_ event is never reset.
A more robust primitive is the so-called "eventcount" which doesn't need to
be reset and avoids the race:
event(); // post: k_ == 0
void signal(); // effects: ++k_
unsigned get(); // returns: k_
void wait( unsigned k ); // block until k_ != k
// ... try_wait ...
Typical use is
for( ;; )
unsigned k = event_.get();
if( predicate ) return;
event_.wait( k );
predicate = true;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk