From: Ron H on
I've been struggling with an odd/even WaitForMultipleObjects() issue. I
defined an array of HANDLEs and used CreateEvent() to create just two
events for two different threads. The ZERO event is the shutdown event and
the ONE event starts an action by the thread. The issue that I've been
chasing is that the threads seemed to respond only to every other
SetEvent().

What I found ( and what solved the issue ) was that I had given the events
for both threads the same name! In both cases I had named event zero
"ShutDown" and event one "StartCycle".

MyEvent[0] = CreateEvent(NULL,FALSE,FALSE,"ShutDown") and
MyEvent[1] = CreateEvent(NULL,FALSE,FALSE,"StartCycle")

Changed the names to "ShutDownThread1", "StartCycle1", "ShutDownThread2",
and "StartCycle2" and all is well.... Since I only referred to the events by
subscript, it didn't occur to me that the name was significant.... think
again! (or maybe just think!)


This is a great group! Thanks for all the help over the years!
Ron H.


From: Goran on
On Feb 24, 12:33 pm, "Ron H" <rnha...(a)nospam.net> wrote:
> I've been struggling with an odd/even WaitForMultipleObjects() issue. I
> defined an array of  HANDLEs and used CreateEvent() to create just two
> events for two different threads. The ZERO event is the shutdown event and
> the ONE event starts an action by the thread. The issue that I've been
> chasing is that the threads seemed to respond only to every other
> SetEvent().
>
> What I found ( and what solved the issue ) was that I had given the events
> for both threads the same name! In both cases I had named event zero
> "ShutDown" and event one "StartCycle".
>
> MyEvent[0] = CreateEvent(NULL,FALSE,FALSE,"ShutDown") and
> MyEvent[1] = CreateEvent(NULL,FALSE,FALSE,"StartCycle")
>
> Changed the names to "ShutDownThread1", "StartCycle1", "ShutDownThread2",
> and "StartCycle2" and all is well.... Since I only referred to the events by
> subscript, it didn't occur to me that the name was significant.... think
> again! (or maybe just think!)

Hmmm... that makes no sense to me. There's normally no need to name
any events that are used for in-process stuff, and can even be harmful
(e.g. when some other process in your session uses same event name).

I would take a look at first FALSE - you use an auto-reset event. If
you have two threads that wait on that, only one will go through. So
that might not be good.

But, as usual, you should show the code that exhibits the problem
first.

Goran.
From: Joseph M. Newcomer on
See below...
On Wed, 24 Feb 2010 05:33:49 -0600, "Ron H" <rnharsh(a)nospam.net> wrote:

>I've been struggling with an odd/even WaitForMultipleObjects() issue. I
>defined an array of HANDLEs and used CreateEvent() to create just two
>events for two different threads. The ZERO event is the shutdown event and
>the ONE event starts an action by the thread. The issue that I've been
>chasing is that the threads seemed to respond only to every other
>SetEvent().
>
>What I found ( and what solved the issue ) was that I had given the events
>for both threads the same name! In both cases I had named event zero
>"ShutDown" and event one "StartCycle".
>
>MyEvent[0] = CreateEvent(NULL,FALSE,FALSE,"ShutDown") and
>MyEvent[1] = CreateEvent(NULL,FALSE,FALSE,"StartCycle")
****
DO NOT GIVE THEM ANY NAME! This code has serious problems, in that if you give the event
a name, it will be shared among EVERY running instance of the program. Unless you
deliberately design a piece of code to share the event with other instances of not only
the process, but any potential process that might ever use the same name (for example, if
you have six completely unrelated apps that all use the event named "Shutdown", then
shutting down the threads in any one of them will shut down the threads in ALL of them,
even though they are completely unrelated!

At least part of how you salvage this is you never, EVER give a name that does not include
a complete GUID as part of the name; that way, cooperating processes from application set
A will not accidentally shut down threads in application set B, which might even have been
written by someone else who never heard of you, but just happened to choose the same name!

So use NULL for the name!
joe
****
>
>Changed the names to "ShutDownThread1", "StartCycle1", "ShutDownThread2",
>and "StartCycle2" and all is well.... Since I only referred to the events by
>subscript, it didn't occur to me that the name was significant.... think
>again! (or maybe just think!)
>
>
>This is a great group! Thanks for all the help over the years!
>Ron H.
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm