473,248 Members | 1,345 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,248 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 11489
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...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

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.