- 论坛徽章:
- 0
|
多线程程序(LINUX),DETACH方式如何使用?
1.always #include <pthread.h>; on the first line of your source code file, otherwise, you can not predict what could happen.
2.pthread_exit() works just like return, so no big deal if you use return instead of pthread_exit(), bu at least you should know that any file opened in the detached thread should be closed before you call any return function.
3.make sure you destroy all the mutextes and conditional variables before you return.
4.if you still can not fix this problem, maybe you should try using pthread_cleanup_push() and pthread_cleanup_pop(), meantimes, never call pthread_exit() from pthread_cleanup_pop() or class's destructor, these kind of actions were definitely not defined.
5.if you still got problem, then I suggest you using commercial debug tools such as insure++, which could hep you trace the runing route.
good luck. |
|