473,378 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

When can WaitForSingleObject return WAIT_FAILED?

When both waiting on an event and a simple unnamed mutex, I'm wondering
when WaitForSingleObject might return WAIT_FAILED. These are both
execution paths I'd very much like to avoid exceptional behavior but I
haven't found much documentation on the specifics. Can anyone offer advice?

Sean

Nov 17 '05 #1
6 11510
Sean Kelly <ke****@pacbell.net> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
When both waiting on an event and a simple unnamed mutex, I'm wondering
when WaitForSingleObject might return WAIT_FAILED. These are both
execution paths I'd very much like to avoid exceptional behavior but I
haven't found much documentation on the specifics. Can anyone offer

advice?

Well, suppose you pass an invalid handle to the function? I'd expect that
you will get a WAIT_FAILED status and then INVALID_HANDLE in the call to
GetLastError(). I don't think there is any way you can avoid checking the
status of the code _somewhere_.

Regards,
Will
Nov 17 '05 #2
William DePalo wrote:
Sean Kelly <ke****@pacbell.net> wrote in message
news:uL**************@TK2MSFTNGP12.phx.gbl...
When both waiting on an event and a simple unnamed mutex, I'm wondering
when WaitForSingleObject might return WAIT_FAILED. These are both
execution paths I'd very much like to avoid exceptional behavior but I
haven't found much documentation on the specifics. Can anyone offer


advice?

Well, suppose you pass an invalid handle to the function? I'd expect that
you will get a WAIT_FAILED status and then INVALID_HANDLE in the call to
GetLastError(). I don't think there is any way you can avoid checking the
status of the code _somewhere_.


This is in an object and ensapsulation ensures that the parameters
passed will always be valid. Basically, I'm trying to avoid the
possibility that an exception may be thrown when acquiring a lock on a
mutex. Critical section operations are guranteed to succeed for this
reason. More info: it's an unnamed mutex without any security
restrictions. Basically, just an object that creates the mutex on
construction, locks/unlocks the mutex when requested, and destroys the
mutex on destruction. What I'm looking for is someone with enough
knowledge of the inner workings of the call that they could tell be what
conditions might cause a WAIT_FAILED in this instance. I'm hoping that
if I can satisfy enough preconditions before calling the function I can
be guranteed that the function will never fail in this way.

Sean

Nov 17 '05 #3
Sean Kelly <ke****@pacbell.net> wrote in message
news:uK**************@TK2MSFTNGP11.phx.gbl...
This is in an object and ensapsulation ensures that the parameters
passed will always be valid.
In an environment where "naked" pointers are used, memory corruption is not
impossible, encapsulation be damned. It is hard to imagine a Win32 program
without a single naked pointer.
What I'm looking for is someone with enough
knowledge of the inner workings of the call that they could tell be what
conditions might cause a WAIT_FAILED in this instance.
Then I suggest that you post again in the kernel group. Perhaps there you'll
run into someone who has seen the source or reverse engineered it.
I'm hoping that if I can satisfy enough preconditions
before calling the function I can be guranteed that
the function will never fail in this way.


Good luck.

Regards,
Will
Nov 17 '05 #4
William DePalo [MVP VC++] wrote:
Sean Kelly <ke****@pacbell.net> wrote in message
news:uK**************@TK2MSFTNGP11.phx.gbl...
This is in an object and ensapsulation ensures that the parameters
passed will always be valid.


In an environment where "naked" pointers are used, memory corruption
is not impossible, encapsulation be damned. It is hard to imagine a
Win32 program without a single naked pointer.
What I'm looking for is someone with enough
knowledge of the inner workings of the call that they could tell be
what conditions might cause a WAIT_FAILED in this instance.


Then I suggest that you post again in the kernel group. Perhaps there
you'll run into someone who has seen the source or reverse engineered
it.


If you're waiting on a mutex, you'll normally get WAIT_FAILED for only two
reasons: 1. The HANDLE you passed in is invalid. 2. Another thread that
owned the mutex was terminated without releasing ownership.

There's no guarantee that those are the only two circumstances though.
There are probably other, extremely rare and esoteric failures possible.

-cd
Nov 17 '05 #5
Carl Daniel [VC++ MVP] wrote:

If you're waiting on a mutex, you'll normally get WAIT_FAILED for only two
reasons: 1. The HANDLE you passed in is invalid. 2. Another thread that
owned the mutex was terminated without releasing ownership.
From what I read in MSDN I thought that case 2 would return
WAIT_ABANDONED and mutex ownership would be transferred.
There's no guarantee that those are the only two circumstances though.
There are probably other, extremely rare and esoteric failures possible.


That's what I'm afraid of. Worst case I suppose I can just always use
critical sections to avoid the possibility of failure.

Sean

Nov 17 '05 #6
Sean Kelly wrote:
Carl Daniel [VC++ MVP] wrote:

If you're waiting on a mutex, you'll normally get WAIT_FAILED for
only two reasons: 1. The HANDLE you passed in is invalid. 2.
Another thread that owned the mutex was terminated without releasing
ownership.


From what I read in MSDN I thought that case 2 would return
WAIT_ABANDONED and mutex ownership would be transferred.


You're right about that.

-cd
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ana | last post by:
Hi! I have problems with the following scenario: My application is developed using C# under .NET. It must run on all Windows versions starting from Windows 98. The user must open different...
0
by: herbert | last post by:
Hi everybody; I've done 2 c++ class; server and client. I would like to make the same in c#. my waiting thread was waiting for 3 type of event: - a socket have data to read - a socket want...
4
by: izik l | last post by:
I have made the following main: void main() { HANDLE myMutex = CreateMutex( NULL, false, NULL ); WaitForSingleObject(myMutex, INFINITE); printf("should never appeared"); }
6
by: Ana | last post by:
Hi! I have problems with the following scenario: My application is developed using C# under .NET. It must run on all Windows versions starting from Windows 98. The user must open different...
5
by: ramialhasan | last post by:
If I have some c++ class exported from a Win32 dll, and from some other console application I created two threads and each thread creates an instance of the exported class. My question is...
1
by: Rachit | last post by:
Hi, I've a WebApp that calls Microsoft CRM WebServices to perform a particular action. In my WebApp I am spawning a new async thread for all the CRM related actions and sending the user to Thank...
6
by: Reji | last post by:
Hi All, I have an MFC dialog based application, where I can browse for files and open them. For opening files I get the file path and use ShellExecute(...). But with ShellExecute(...), i lose...
1
by: stefan.sedich | last post by:
Hi I am trying to open an email in outlook with the following string command = "c:\\Program Files\\Microsoft Office\\OFFICE11\\OUTLOOK.EXE c:\\a.msg"; StartupInfo si = new StartupInfo();...
10
by: blisspikle | last post by:
I see a lot of examples posted for Waitforsingleobject API for Processes or threads, but not events. I cannot get waitforsingleobject to subscribe to an event. I use a class PLCEthernet which is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.