copying some data I had for working boost threads, I implemented the following code below.
I get the error C:\dev\default threads_threads.cpp|18|error: invalid conversion from ‘void ()(void)’ to ‘unsigned int (attribute((stdcall)) )(void)’ [-fpermissive]|
but… the commented lines are what was recommended, and a comment explains the error I got.
it turns out _beginThreadEx is highly recommended, but poorly documented (as in tutorials) on the web
#include <iostream>
#include <process.h>
void myThread(void *data)
{
//C:\dev\default threads\_threads.cpp|6|error: invalid conversion from 'int*' to 'int' [-fpermissive]|
//int x = static_cast<int*>(data);
int *x = (int*)data;
std::cout << "Hellow World! " << x;
}
int main()
{
int x = 10;
_beginthreadex(NULL, 0, myThread, &x, 0, NULL);
while(true);
}
You have to declare x as pointer anyway:
both
_beginthreadand_beginthreadexare documented here: http://msdn.microsoft.com/en-us/library/kdzttdcb(v=vs.80).aspxAccording to the declaration of _beginthreadex() your myThread() function should be declared like this: