线程等待
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
{
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
相关文章推荐
- Windows系统下等待线程退出的方法
- 主线程中使用join等待所有子线程执行结束
- java中一个线程等待另一个线程执行完后再执行
- 第三节:ThreadPool的线程开启、线程等待、线程池的设置、定时功能
- 线程间通讯--ResourceDemo2 --等待/唤醒机制
- jconsole线程面板中的阻塞总数和等待总数
- Linux驱动的等待队列、轮询及内核线程
- Java多线程基础 线程的等待与唤醒(wait、notify、notifyAll)
- WaitForSingleObject 等待线程句柄
- 检测委托线程的结束_通过等待句柄和回调函数
- java 分别利用synchronized和jdk1.5新特性实现多消费者-多生产者线程的等待唤醒机制
- 线程间的通信--等待唤醒机制
- Java多线程--让主线程等待所有子线程执行完毕代码
- java基础12:线程间通信----等待唤醒机制
- MFC 主界面函数中线程等待避免界面卡死的处理方法
- dubbo连接zookeeper注册中心因为断网导致线程无限等待问题【转】
- Java并发:主线程等待多个子线程执行完才继续执行
- Java多线程系列--“基础篇”05之 线程等待与唤醒
- 线程:Java主线程等待子线程结束
- 1.3.线程基础_等待线程