|
Boost : |
From: Sean Kelly (sean_at_[hidden])
Date: 2004-01-26 10:57:33
Just a quick correction because I know someone will point it out. The
manual reset method will wake up all threads waiting on an event. The
auto reset method is supposed to wake up only a single thread waiting on
an event and to remain signaled if there are no threads waiting. If for
some reason this doesn't work as documented (which is what the rational
page seems to imply) then the example below might be a workable
substitute. Could comeone elucidate on what's said in the rationale page?
I can't say I've had any problems with events myself and I'm curious what
the reasoning is.
mutex sync;
queue<T> mq;
event ev;
LONG signal( 0 );
void add_message( T const& msg ) {
lock l( sync );
mq.add( msg );
ev.set();
InterlockedExchange( &signal, 1 );
}
void process_msgs() {
// synchronized access to mq
// acts on messages
}
void loop() {
for(;;) {
while( !InterlockedCompareExchange( &signal, 0, 1 ) ) {
ev.wait();
ev.reset();
}
process_msgs();
}
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk