69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <Windows.h>
#include <time.h>
#include <process.h>
volatile LONG g_bCon;
void printThread(void* pArg)
{
int i = 0; while(g_bCon)
{
printf("%d\n",i++);
}
}
void countThread(void* pArg)
{
_beginthread(printThread,0,0);
Sleep(1000);
g_bCon = 0;
}
int main(int argc, char* argv[])
{
g_bCon = 1;
_beginthread(countThread,0,0);
system("pause"); /*这里必须要暂停下*/
return 0;
}
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&tid, &attr, routine, NULL);
。