CreateThread()创建与终止线程
![在这里插入图片描述](https://img-blog.csdnimg.cn/2019122122001257.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzExODA3Mw==,size_16,color_FFFFFF,t_70)
#include <windows.h>
#include <stdio.h>
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
printf("Sub thread started\n");
printf("Sub thread finished\n");
return 0;
}
int main(int argc,char* argv[])
{
DWORD threadID;
HANDLE hThread=CreateThread(NULL,0,ThreadProc,NULL,0,&threadID);
WaitForSingleObject(hThread,INFINITE);
CloseHandle(hThread);
return 0;
}
beginthread()创建和终止线程
#include <windows.h>
#include <stdio.h>
#include <process.h>
void _cdecl ThreadProc(void *para)
{
printf("Sub thread started\n");
printf("Sub thread finished\n");
}
int _tmain(int argc,_TCHAR* argv[])
{
DWORD threadID;
HANDLE hThread=(HANDLE)_beginthread(ThreadProc,0,NULL);
WaitForSingleObject(hThread,INFINITE);
return 0;
}