CreateThread问题 代码为什么会执行两次printf("Now new ThreadID = %d\n",dwThreadId);
#include<stdio.h>#include<windows.h>DWORDWINAPIThreadPro(LPVOIDlpParam){inti=0;while(...
#include <stdio.h>
#include <windows.h>
DWORD WINAPI ThreadPro(LPVOID lpParam)
{
int i = 0;
while(i<5)
{
printf("%d\n",i++);
}
return 0;
}
int main(int argc,char* argv[])
{
HANDLE hThread;
DWORD dwThreadId;
//printf("Test\n");//此处取消注释,下面的输出语句只执行一次!???
hThread = ::CreateThread(
NULL,
NULL,
ThreadPro,
NULL,
0,
&dwThreadId);
printf("Now new ThreadID = %d\n",dwThreadId);
::WaitForSingleObject(hThread,INFINITE);
::CloseHandle(hThread);
return 0;
} 展开
#include <windows.h>
DWORD WINAPI ThreadPro(LPVOID lpParam)
{
int i = 0;
while(i<5)
{
printf("%d\n",i++);
}
return 0;
}
int main(int argc,char* argv[])
{
HANDLE hThread;
DWORD dwThreadId;
//printf("Test\n");//此处取消注释,下面的输出语句只执行一次!???
hThread = ::CreateThread(
NULL,
NULL,
ThreadPro,
NULL,
0,
&dwThreadId);
printf("Now new ThreadID = %d\n",dwThreadId);
::WaitForSingleObject(hThread,INFINITE);
::CloseHandle(hThread);
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询