2011-10-27 32 views

回答

4

您可以在线程函数的很早阶段使用pthread_cleanup_push(3)。赋予pthread_cleanup_push的函数可以设置一个“观察者”线程可以拾取的标志。 pthread_cleanup_push也受到pthread_exit的支持,并且不受例外的限制。

编辑:用析构函数使用pthread_key_create(3)和线程函数调用初pthread_setspecific(3):要做到这一点的第二种方式。析构函数可以向观看线程发出即将死亡的信号。

1

你可以简单地使用pthread_cleanup_push和pthread_cleanup_pop执行的线程退出清理处理程序。这将捕获cancel/pthread_exit事件。

相关问题