帮忙看段简单的程序!
程序如下:
#include <stdio.h>
#include <windows.h>
DWORD WINAPI HelloFunc(LPVOID arg)
{
int *a ;
a = (int* ) (arg);
printf("Helle func!%d\n",*a);
return 0 ;
}
void main()
{
int a[1];
LPVOID arg;
HANDLE hThread[4];
for(int index = 0; index < 4; index++)
{
*a = index;
arg = (LPVOID)a;
hThread[ index ] =
CreateThread(NULL,0,HelloFunc,arg,0,NULL);
//Sleep(1);
}
Sleep(20);
}
我运行了很多次,为什么输出总是:
Helle func!3
Helle func!3
Helle func!3
Helle func!3