Im trying to call _beginthread with multiple arguments but I get undefined behavior.
It either wont be called or just idles forever without printing out anything.
Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <process.h>
#include <string>
#include <iostream>
using namespace std;
typedef struct
{
string data1;
string data2;
} t;
t arg;
void Thread(void *param)
{
cout << " Thread \n";
t *args = (t*) param;
string x = args->data1;
string y = args->data2;
cout << x << y << " \n";
_endthread();
}
void foo(string a, string b)
{
arg.data1 = a;
arg.data2 = b;
HANDLE handle = (HANDLE) _beginthread(Thread, 0, (void*) &arg);
cout << " foo " << handle << "\n";
}
int main()
{
foo("Hello"," World");
return 0;
}