WaitForMultipleObjects Problem!

Started by
10 comments, last by Codeka 14 years, 8 months ago
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
Advertisement
Is mDoneEvents.size() less than MAX_WAIT_OBJECTS (64 I believe)?
What's the value of size? Less than 64 or MAXIMUM_WAIT_OBJECTS?
Arr yes should have said its 4 (Num of cores on my machine)
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.
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 :)
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.
What O/S is this on? Windows CE, for example, does not support WaitAll=TRUE.
You have to use different names I believe, as described in the documentation for CreateEvent.
Again my bad not including all the info I should have done, Windows Vista 64bit.

This topic is closed to new replies.

Advertisement