Original Post
🔒 Locked
WaitForMultipleObjects
Advertisement
Probably by returning -1 (ie WAIT_FAILED). If you're confronting that return value, call GetLastError and plug the result from that into FormatMessage to get a error message string with information about the error. See Retrieving the Last-Error Code for sample code.
handle is an array of handles.
WaitForMultipleObjects always gives me -1. What am I doing wrong?
-Greg
for( int i = 0; i < MAX_THREADS; i++ ) handle = CreateEvent(null, true, true, null);...DWORD index = WaitForMultipleObjects(MAX_THREADS, handle, false, INFINITE);if( index != WAIT_FAILED ){ CloseHandle(handle[index-WAIT_OBJECT_0]); handle[index-WAIT_OBJECT_0] = CreateEvent(null, true, false, null);}WaitForMultipleObjects always gives me -1. What am I doing wrong?
-Greg
That exact code works fine for me. On a side note, you don't need to destroy and re-create the event. You can use ResetEvent() to set the state of the event to nonsignalled.
Perhaps your handles are being closed somewhere else in your code (but not set to NULL)? That'll cause GetLastError() to give you an error about an invalid handle I expect.
Perhaps your handles are being closed somewhere else in your code (but not set to NULL)? That'll cause GetLastError() to give you an error about an invalid handle I expect.
Good point. I have changed my code accordingly, however I am still only getting WAIT_FAILED and the extended error message is:
failed with error 87: The parameter is incorrect.
What parameter is incorrect? They all look correct.
DWORD WaitForMultipleObjects(
DWORD nCount,
const HANDLE* lpHandles,
BOOL bWaitAll,
DWORD dwMilliseconds
);
#define MAX_THREADS 128
...
HANDLE handle[MAX_THREADS];
...
DWORD index = WaitForMultipleObjects(MAX_THREADS, handle, false, INFINITE);
failed with error 87: The parameter is incorrect.
What parameter is incorrect? They all look correct.
DWORD WaitForMultipleObjects(
DWORD nCount,
const HANDLE* lpHandles,
BOOL bWaitAll,
DWORD dwMilliseconds
);
#define MAX_THREADS 128
...
HANDLE handle[MAX_THREADS];
...
DWORD index = WaitForMultipleObjects(MAX_THREADS, handle, false, INFINITE);
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement