主题:最近两天学习线程,有个不明白的运行结果,求教!
代码如下,运行结果会出来两行Create thread succeed!,实在不解!
------------------------------------------------------------------------
#include<stdio.h>
#include<windows.h>
#include<conio.h>
DWORD WINAPI ThreadProc(LPVOID lpParam);
void main(void)
{
HANDLE hThread;
DWORD lpParam;
DWORD ThreadID;
hThread = CreateThread(NULL, 0, ThreadProc, &lpParam, 0, &ThreadID);
if(NULL == hThread)
{
printf("Create thread failed!\n");
}
else
{
printf("Create thread succeed!\n");
_getch( );
CloseHandle(hThread);
}
}
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
int i;
for(i=0;i<10;i++)
printf("%d\n",i);
return 0;
}
------------------------------------------------------------------------
#include<stdio.h>
#include<windows.h>
#include<conio.h>
DWORD WINAPI ThreadProc(LPVOID lpParam);
void main(void)
{
HANDLE hThread;
DWORD lpParam;
DWORD ThreadID;
hThread = CreateThread(NULL, 0, ThreadProc, &lpParam, 0, &ThreadID);
if(NULL == hThread)
{
printf("Create thread failed!\n");
}
else
{
printf("Create thread succeed!\n");
_getch( );
CloseHandle(hThread);
}
}
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
int i;
for(i=0;i<10;i++)
printf("%d\n",i);
return 0;
}