//ThreadInThread.cpp
#include "stdafx.h"
#include <stdio.h>
#include <process.h>
#include <windows.h>
int g_nCount;
unsigned int __stdcall SubThreadFun(PVOID pM)
{
while(true)
{
printf("subthread\n");
Sleep(1000);
}
return 0;
}
unsigned int __stdcall ThreadFun(PVOID pM)
{
_beginthreadex(NULL, 0, SubThreadFun, NULL, 0, NULL);
while(true)
{
printf("mainthread\n");
Sleep(1000);
}
return 0;
}
int main()
{
const int THREAD_NUM = 1;
HANDLE handle[THREAD_NUM];
g_nCount = 0;
for (int i = 0; i < THREAD_NUM; i++)
handle[i] = (HANDLE)_beginthreadex(NULL, 0, ThreadFun, NULL, 0, NULL);
WaitForMultipleObjects(THREAD_NUM, handle, TRUE, INFINITE);
return 0;
}
在线程里开线程
最新推荐文章于 2022-12-24 21:37:24 发布