This code here is giving segmentation fault. Any clues why? also any general tips for writing good multi-threaded code are welcome.
#include <windows.h>
#include <process.h>
#include <iostream>
using namespace std;
unsigned __stdcall Display(void* p)
{
Sleep(500);
cout << "Display" << endl;
cout << *((int*)p) << endl;
return 0;
}
int main()
{
unsigned taddr = NULL;
unsigned createFlag = 0;
for(int i=0;i<5;i++)
{
if (_beginthreadex(NULL,0,Display,&i,createFlag,&taddr))
{
cout << "success" << endl;
}
else
cout << "failed" << endl;
}
cout << "main's execution is over" << endl;
ExitThread(0);
}