Solved

WaitForSingleObject()

Posted on 2002-07-08
7
2,690 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Describe order of operation while copying text 11 115
Handling string inputs in C/Linux 23 179
List out all word 7 255
Unable to start eclipse ? 17 128
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now