Answer the question
In order to leave comments, you need to log in
How to pass two parameters to a thread?
How to pass 2 parameters to a thread: a pointer to an array and its size. Just a pointer is not enough, and then its size cannot be determined there.
So now:
int *array = new int[mSize];
HANDLE hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)a,&array,0,&tid);
int a(int *array)
{
min = array[0]; max = array[0];
for (i = 0; i < mSize; i++) { sum += array[i]; Sleep(12); }
cout << "Sum :" << sum << endl;
for (i = 0; i < mSize; i++){if (min > array[i]) min = array[i];}
cout << "Min :" << min << endl;
return 0;
}
Answer the question
In order to leave comments, you need to log in
You can create new int[mSize+1], write the size in the first cell, use the rest for your own purposes... And in the thread, the size from the same array and extract
Because C++ is an object language, the discussion of how to communicate something must be in terms of objects.
It's not assembler. Look at the header of the function for creating a thread.
HANDLE CreateThread(
LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
__drv_aliasesMem LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question