Solved

WaitForSingleObject()

Posted on 2002-07-08
7
2,693 Views
Last Modified: 2008-03-03
Hello Expert,

Have A Thread that in some point calls:
WaitForSingleObject(hEvent, INFINITE);

The event object is created like this:
hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

At some other point,
SetEvent(hEvent);
is called.

The problem:
The thread does not response to the "signaling" of hEvent an remains blocked.

Can you think about a reason for this ?

TIA,
Oren.
0
Comment
Question by:orenm
7 Comments
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7140293
Well, first obvious questions: are you sure the CreateEvent() call succeeded? What results do you get if you call GetLastError() after the CreateEvent() and SetEvent() calls?
0
 

Author Comment

by:orenm
ID: 7140403
The CreateEvent() and SetEvent() calls are successful:
GetLastError() returns with 0 and the message:
"The operation completed successfully."

Oren.
0
 
LVL 10

Expert Comment

by:makerp
ID: 7140475
try

CreateEvent(NULL,TRUE,FALSE,NULL)
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Accepted Solution

by:
weicco earned 100 total points
ID: 7140979
How are threads created and how the event handle is passed to threads?

If you create new thread and doesn't enable handle inheritance or you created event without handle inheritance, new thread doesn't get handle to event.

But if you use global variable to store and access event handle this shouldn't be the problem.
0
 

Author Comment

by:orenm
ID: 7142349
Some more information:

Same process (no security inheritance needed).
The event handles are static/global and not passed to the threads.

The application creates 2 identical threads like this:
m_hThread = (HANDLE)_beginthreadex(0, 0, ..., ..., 0, 0);

This should be interesting:
The WaitForSingleObject() DOES continue in case that SetEvent() is called from the "twin" thread.
The original problem is true in case that SetEvent() is called by the "main" thread.

hope this new information will help to make conclusions.

Oren.

P.S.
Actually this threads code is embedded in some C++ classes but this doesn't look significant.
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7142686
Er...just a second, if the main thread is blocking on a WaitForSingleObject() call, how is it ever going to reach the code which calls SetEvent()?
0
 

Author Comment

by:orenm
ID: 7142771
Well, the bug is found.

for the interested and the familiar with C++:
The event handler was created in a constructor which actually invoked more then once for some objects, so,
the WaitForSingleObject() and SetEvent() had the same name of event handler, but,
actually relating to different handlers.

Thanks any way.

weicco, you were the closest, so you get the points.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
memory mapped I/O query 6 147
Problem in finding output of a program 11 104
chcp 65001 File encoding 66 246
smtp c source code 7 67
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question