Consider the code below:
for (int i = 0; i < thread_number; i ++)
hThreadArray[i] = CreateThread(
0,
0,
single_thread_function_name,
(LPVOID)i,
0,
&dwThreadIdArray[i]);
WaitForMultipleObjects(thread_number, hThreadArray, TRUE, INFINITE);
It works correctly on 32 bit platform, but on 64 bit it crashes.
The crash happens in the WaitForMultipleObjects function.
Anyone know what i’m doing wrong?
Edit:
hThreadArray is declared as:
HANDLE* hThreadArray;
hThreadArray = (HANDLE*) malloc (thread_number * sizeof(HANDLE));
The single_thread_function_name as:
DWORD WINAPI single_thread_function_name( LPVOID lpParam ){
.....
return 0;
}
hThreadArray is not an array, just a pointer, it certainly should crash. It is strange how it works on 32-bit platform.
As hThreadArray is malloced, maybe it does not meet 64-bit alignment requirements. Try with: