Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WaitForSingleObject Crashes

Status
Not open for further replies.

hankgao0703

Programmer
Jul 18, 2001
27
CA
When I debug my application in IDE, I find sometimes when I call WaitforSingleObject which waits a event object, the whole application crashes, and the following message is given:
Unhandled exception in blabla.exe: 0xC0000005: access violation

My concern is that if the event handle which is passed to WaitforSingleObject is an invalid one, the call will crash???

and, if the handle is valid, then in what kind of situation, the call to WaitforSingleObject fails?

By the way, how do I know a handle is a valid event object handle?

Thanks in advance!

 
Some supposes
1. Is Your handle one of:
Change notification
Console input
Event
Job
Mutex
Process
Semaphore
Thread
Waitable timer ?
2. If You works on WinNT/2000/XP:
The handle must have SYNCHRONIZE access. Does it?
3. What returns WaitforSingleObject? May be a handle is valid by start of WaitforSingleObject, but for example by multithreading You become invalid handle before WaitforSingleObject returns.
4. What says GetLastError()?
5. May be You have an error before WaitforSingleObject (a very bad memory overflow could cause a lot of another errors)?
 
Thanks for your response.

1. My handle is an event

2. I work on Windows 2000, and I don't give the handle a SYNCHRONIZE access, but if I don't, the call to WaitForSingleObject will crash?

3,4: As WaitforSingleObject crahes, I have no way to know what returns and I don't have opportunity to call GetLastError. (Again, maybe the handle becomes invalid where it is valid when WaitforsingleObject is called, the call will crash? and I don't think every single time when I call WaitforsingleObject, the handle is made invalid by another thread. It's hard to do this from within another thread :)

5. I guess so, maybe somewhere memory overlow before the function is called.(I really really don't hope this because my program is quite big)

Things become interesting, yeah?
 
Thanks for your response.

1. My handle is an event

2. I work on Windows 2000, and I don't give the handle a SYNCHRONIZE access, but if I don't, the call to WaitForSingleObject will crash?

3,4: As WaitforSingleObject crahes, I have no way to know what returns and I don't have opportunity to call GetLastError. (Again, maybe the handle becomes invalid where it is valid when WaitforsingleObject is called, the call will crash? and I don't think every single time when I call WaitforsingleObject, the handle is made invalid by another thread. It's hard to do this from within another thread :)

5. I guess so, maybe somewhere memory overlow before the function is called.(I really really don't hope this because my program is quite big)

Things become interesting, yeah?
 
If the handle does not have a SYNCHRONIZE access, the call to WaitForSingleObject on Win2K will crash.
And why You can't know what GetLastError() returns? Call it after WaitForSingleObject() and look in debugger; if You work with release, You can use printf with console and MessageBox with Windows...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top