Re: COM objects waiting on a shared resource
Jason S <jmsachs@gmail.com> wrote:
On Apr 16, 1:42 pm, "Igor Tandetnik" <itandet...@mvps.org> wrote:
Can't you do SetEvent to signal the condition, and then whichever
thread acquires the mutex does ResetEvent right away? Clearly at
least one thread would get through this way.
Getting one thread through isn't the issue (I can just use an auto-
reset event for that), it's multiple threads. Let's say I have 3 COM
objects A, B, C: A and B are waiting for something to happen, and
eventually C sets the something to happen and signals the condvar, at
which point A and B are supposed to wake up. Then either one of them
gets hold of the mutex, does its thing, releases, then the other gets
hold of the mutex, does its thing, and releases, *or* I use
InterlockedXXX() functions and both A and B do their thing
(theoretically at the same time...).
Right. I imagined the same thing. So the threads A and B will do
something like this:
WaitFor(event);
WaitFor(mutex);
ResetEvent(event);
DoSomething();
ReleaseMutex(mutex);
Thread C will just do
SetEvent(event);
at which point both A and B wake up, but only one of them gets the
mutex. Some time later, the other one gets the mutex.
The problem is that I can't find a synchronization primitive that will
release multiple threads *and* allow me to process STA messages in the
meantime.
Manual-reset event. Just don't reset it right away.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925