Reputation: 3434
I have a vector of event objects, which is used in WaitForMultipleObjects
function. After an event is signalled I tried to close the event using the close handle function, but I am getting an error like Invalid handle was specified
. Can anybody tell that what the issue is?
std::vector<HANDLE> eventVector;
//..
// Entering data to vector
size_t count = eventVector.size();
DWORD signaledEvent;
While(count > 0)
{
if (WAIT_OBJECT_0 == (signaledEvent = WaitForMultipleObjects(handleVector.size(),handleVector.data(), false, INFINITE)))
CloseHandle(handleVector[signaledEvent - WAIT_OBJECT_0]); // Here I am getting error.
count--;
}
Upvotes: 0
Views: 525
Reputation: 69632
On the first iteration it possibly worked out well, but then once you close the handle, you cannot supply the same vector to WaitForMultipleObjects
once again: at least one of the handles is no longer valid.
So WaitForMultipleObjects
returns you an error there, and possibly another one later in CloseHandle
.
This is not your real code, right? Because in this code snippet you don't really check returned values for errors. Because this code snippet has more errors to note:
WAIT_OBJECT_0 + 0
only, and not other WAIT_OBJECT_0 + N
Upvotes: 1