سؤال

I am using WaitForMultipleObject function with waitForAll parameter = true. Here using a std::vector of handle object to wait for. If this function is timed out, then how can i identify that waiting on which handle is timed out??.

if(WAIT_OBJECT != WaitForMultipleObject(vector.size(), vector.data(), true, 16000))
{
//get the event that causes the wait to time out(assume that only one object is timed out.others are successfully set.)
}
هل كانت مفيدة؟

المحلول

According to MSDN's WaitForMultipleObjects function definition:

Return value minus WAIT_OBJECT_0 indicates the array index of the object that satisfied the wait. If more than one object became signaled during the call, this is the array index of the signaled object with the smallest index value of all the signaled objects.

So, you just need to check: if the function succeeded - it's all OK, if not, than check what kind of handles were in the array and the ones which weren't. Thus you can figure out the problematic handle.

Also, I suggest you take a look at the SignalObjectAndWait function. Its behaviour is different, but maybe you will find it useful in some cases.

نصائح أخرى

you said you are using WaitForMultipleObject but your code is showing WaitForSingleObject. Assuming you are using WaitForMultipleObject and if you said true to the parameter it means the function returns when the state of all objects in the vector is signaled .

so in your case if it is timed out none of your objects are signaled.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top