Re: CMultiLock example
Stephen Wolstenholme wrote:
I can't fathom out how to use CMultiLock.
Anyone know of a good example?
I can find examples that don't work but I would like to study an
example that does work.
Steve
OK, I just wrote this example, but you can tell me if you think it won't work:
CEvent evtThread1, evtThread2, evtThread3;
// assume these events have been created and have some meaning somewhere
CSyncObject * apEvents[] = { &evtThread1, &evtThread2, &evtThread3 };
CMultiLock lockmany( apEvents, _countof(apEvents), FALSE );
DWORD dwResult = lockmany.Lock( 5000, FALSE );
switch ( dwResult )
{
case WAIT_OBJECT_0:
case WAIT_OBJECT_0+1:
case WAIT_OBJECT_0+2:
{
DWORD dwEvt = dwResult - WAIT_OBJECT_0;
// do something in response to the event apEvents[dwEvt];
}
break;
case WAIT_TIMEOUT:
// Do something if timeout expired
break;
case WAIT_ABANDONED:
// Do something if wait abandoned
break;
}