您的位置:首页 > 其它

线程等待

2012-09-15 22:55 302 查看
void *func(void *args)

{

Sleep(2);

printf("this is func!\n");

}

void main()

{

pthread_t pid;

if(pthread_create(&pid, NULL, func, NULL))

{

return -1;

}

/*

用于等待一个线程的结束

如果代码中没有pthread_join,主线程会很快结束,从而使整个进程结束,从而使创建的线程pid没有机会

开始执行就结束了

*/

pthread_join(pid, NULL);

printf("this is end of main!\n");

return;

}

编译:

gcc wait.c -o wait -lpthread
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: