Click here to Skip to main content
15,921,382 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
for( int nIterator = 0; nIterator< 100; nIterator++ )
{
m_hThread[ nIndex++ ] = CreateThread( NULL,0,( LPTHREAD_START_ROUTINE )FileWriteOne,this,0,NULL );
m_hThread[ nIndex++ ] = CreateThread( NULL,0,( LPTHREAD_START_ROUTINE )FileWriteTwo, this,0,NULL );
}
DWORD dwRet = WaitForMultipleObjects( nIndex, m_hThread, FALSE, INFINITE );
DWORD dwLastErr = GetLastError();

The return value of WaitForMultipleObjects handle is 87.This shows an error that “parameters are incorrect”. but the parameters are correct.If there is only 10 threads,it will return 0 else it will return 87.So What I have to do to correct this error??
Posted
Comments
Albert Holguin 1-Jun-11 10:23am    
...also, NEVER use INFINITE wait times, that's a horrible, unsustainable practice that can lead to a lot of problems...

it is beacuse the maximum number of wait object allowed is 64.

#define MAXIMUM_WAIT_OBJECTS 64 // Maximum number of wait objects
in WINNT.h

here you are waiting for nearly 200 objects which is not possible.
nIndex value will be above 64 since each iteration creats 2 threads.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jun-11 1:03am    
Wow, I did not pay attention for the numbers. My 5.
Nevertheless, what OP reports looks like an expected result, as I say in my answer.
--SA
charutha 1-Jun-11 1:54am    
Thanks
This is expected return. This is not "parameters are incorrect".

The parameter FALSE in your call to WaitForMultipleObjectsthat indicates that you're waiting for the state of any of the thread objects to be signaled. The return value is this case is the index in the wait object array. Sometimes this is very first thread (return of 0), sometimes this is the thread with the index of 87. Thread index is 0-based because the shift is defined as WAIT_OBJECT_0 = 0.

Read more thoroughly: http://msdn.microsoft.com/en-us/library/ms687025(v=vs.85).aspx[^].

No problem, in fact.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900