I’m attempting to do some basic parallelisation using _beginthreadex, and passing parameters as per an example I was given, but it won’t work.
Any ideas?
#include <iostream>
#include <process.h>
void MyThread(void *data)
{
std::cout << "Hello World!";
}
int main()
{
_beginthreadex(NULL, 0, MyThread, NULL, 0, NULL);
while(true);
}
EDIT:
Why won’t passing NULL as an argument work? (Since the function takes no arguments anyway?)
Passing NULL as an arguments list worked fine with _beginthread.
Your code has two errors in it, neither of which are related to the parameter to the thread function —
NULLis fine for that, as you surmised.The problems are in the signature of the thread function, and the error you are getting points this out. Firstly, it must be a
__stdcallfunction, and secondly it must return anunsigned int. Your function is__cdecland returnsvoid.should fix the problem for you.