WaitForMultipleObjects Problem!

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 on other sites
Is mDoneEvents.size() less than MAX_WAIT_OBJECTS (64 I believe)?

Share on other sites
What's the value of size? Less than 64 or MAXIMUM_WAIT_OBJECTS?

Share on other sites
Arr yes should have said its 4 (Num of cores on my machine)

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 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 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 on other sites
What O/S is this on? Windows CE, for example, does not support WaitAll=TRUE.

Share on other sites
You have to use different names I believe, as described in the documentation for CreateEvent.

Share on other sites
Again my bad not including all the info I should have done, Windows Vista 64bit.

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 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.

Create an account

Register a new account

• Partner Spotlight

• Forum Statistics

• Total Topics
627654
• Total Posts
2978453

• 10
• 12
• 22
• 13
• 33