Sign in to follow this  

WaitForMultipleObjects Problem!

This topic is 3043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All I have a strange problem with WaitForMultipleObjects. If I try and do a wait on multiple objects with the line:
DWORD status = WaitForMultipleObjects(mDoneEvents.size(), &mDoneEvents[0], TRUE, INFINITE);
I get WAIT_FAILED returned with and Error of 87 Parameter Incorrect. The vector of HANDLE's is valid and if I do a WaitForSingleObject on each member of mDoneEvents all works fine, also if I set the bwaitAll flag to FALSE ie:
DWORD status = WaitForMultipleObjects(mDoneEvents.size(), &mDoneEvents[0], FALSE, INFINITE);
Then it works just fine, problem is I need the waitall to be TRUE, does anyone have any idea what I may have done wrong here? Many thanks Chris

Share this post


Link to post
Share on other sites
Is mDoneEvents an std::vector<HANDLE>?
Are they all the same type of objects, and how do you create them?
If you use FALSE for bWaitAll what is the return code?
And does it always return immediately, or can you actually get a blocking wait with FALSE for a while, if you don't signal the events?

My first action would be to inspect the vector of events, to make sure there are only four elements in it and that every handle is valid. Perhaps you have a duplicate?

From the documentation WaitForMultipleObjects:
Quote:

An array of object handles. For a list of the object types whose handles can be specified, see the following Remarks section. The array can contain handles to objects of different types. It may not contain multiple copies of the same handle.

If one of these handles is closed while the wait is still pending, the function's behavior is undefined.

The handles must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.

Also read the Remarks section carefully.

Share this post


Link to post
Share on other sites
mDoneEvents is a std::vector<HANDLE> and I use
HANDLE event = CreateEvent(NULL, TRUE, FALSE, "Done");
mDoneEvents.push_back(event);



When I use FALSE for bwaitAll the return code is 0 and it will block correctly until a mDoneEvent is set, expected behaviour.

I should also say I would run this through the debugger to check but it's part of a plugin for 3ds max and that excludes the use of the debugger.

Checked the vector, its got 4 proper HANDLE's all different that work fine with WaitForSingleObject, SetEvent, ResetEvent etc so Iam assuming the HANDLE's are valid and havnt been corrupted.

Thanks for you suggestions, reading the MSDN page for the Nth time very carefully :)

Share this post


Link to post
Share on other sites
You should still be able to attach your debugger to the program. For example, with MSVC, if you load up your project and use Debug->Attach to Process you should be able to debug your own DLL code.

Share this post


Link to post
Share on other sites
Thankyou all for your quick replies and a big thanks to Erik, it was indeed the use of a "Done" in CreateEvent that was the problem, setting to NULL and all works fine, thankyou again :) Ratings to All :)

Share this post


Link to post
Share on other sites
The problem is that you've given them all the same name (it seems) which means they're actually all the same event.

In general, you shouldn't need to give your events (or mutexes or any other synchronization objects) a name unless you want to share them between processes.

Share this post


Link to post
Share on other sites

This topic is 3043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this