pthread_join with timeout
2014-05-05 18:41
1346 查看
http://www.linuxquestions.org/questions/programming-9/pthread_join-with-timeout-365304/
void * threadfunc (void *) { while (!my_quit) { /* do a bunch of stuff */ } /* signal waiting threads that this thread is about to terminate */ pthread_mutex_lock(&my_mutex); pthread_cond_broadcast(&my_cond); pthread_mutex_unlock(&my_mutex); return NULL; } void stop_the_thread (void) { int e; my_quit = true; /* wait (with timeout) until thread has finished */ pthread_mutex_lock(&my_mutex); e = pthread_cond_timedwait(&my_cond, &my_mutex, &my_timeout); pthread_mutex_unlock(&my_mutex); /* now join so we wait until thread has -really- finished */ if (e == ETIMEDOUT) { printf("Timed out waiting for thread to exit :_(\n"); pthread_cancel(my_thread); /* try to forcefully stop it at a cancellation point */ } else pthread_join(my_thread); }
相关文章推荐
- ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
- pthread_join函数及linux线程
- pthread_join监控线程退出的状态
- pthread_join/pthread_exit用法实例
- llvm Build error of pthread with gcc4.6
- pthread 基础篇 pthread_join
- ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
- Entity Framework include with left join is this possible?
- 多线程之pthread_detach和 pthread_join
- pthread_join 两次同一个线程
- pthread_join与pthread_detach细节问题
- 随笔日记: 一个daemon程序,它的pthread_join()经常意外返回, 很是奇怪!
- pthread_join的段错误
- MessageBox With Timeout
- Pthread创建线程后必须使用join或detach释放线程资源
- TAU G2的错误信息:TSC0134: Transition must end with stop, nextstate or join action
- 父子进程之间的参数传递和数据返回 pthread_create & pthread_join
- AJAX Timeouts with Prototype
- pthread_join
- 多线程编程实例---pthread_join函数详解