------解决方案-------------------- 一般不会出现单个线程挂掉的情况吧,除非程序逻辑上有问题,被线程被别的线程cancel或者自己在不该退出的地方用了pthread_exit了,要挂也是整个进程挂了。
如果真出现这种情况,肯定会死锁了。
楼主可以看看pthread_cleanup_push()/pthread_cleanup_pop()这两个函数,,就是处理LOCK和UNLOCK之间被cancel的情形的。
man pthread_cleanup_push中的一段话:
for example, unlock a mutex
so that it becomes available to other threads in the process.
...
A cancellation clean-up handler is popped from the stack and executed
in the following circumstances:
1. When a thread is canceled, all of the stacked clean-up handlers are
popped and executed in the reverse of the order in which they were
pushed onto the stack.
2. When a thread terminates by calling pthread_exit(3), all clean-up
handlers are executed as described in the preceding point. (Clean-
up handlers are not called if the thread terminates by performing a
return from the thread start function.)
3. When a thread calls pthread_cleanup_pop() with a nonzero execute
argument, the top-most clean-up handler is popped and executed. ------解决方案--------------------