pthread_cleanup_push() & pthread_cleanup_pop()




.

pthread_cleanup_push() 一般用于线程结束时回调一些函数,push顾名思义向stack中压入一个函数。通过宏展开实现,展开后带有一个{
pthread_cleanup_pop()  一般就设成0了,用于和push匹配,宏展开后带有},如果不一一对应,编译一定会报错,因为{}不匹配。

stack内的函数只有在以下条件下会被调用

线程通过pthread_exit()函数退出 线程被pthread_cancel()取消 pthread_cleanup_pop(int execute)时,execute传了一个非0值
phread_join(pthread_t tid, void **value_ptr)中,value_ptr传回被join的线程的返回值,该返回值通过
pthread_exit(void *return_value)的参数来传递
线程通过pthread_exit()函数退出 线程被pthread_cancel()取消 pthread_cleanup_pop(int execute)时,execute传了一个非0值

猜你喜欢

转载自blog.csdn.net/qq_38255689/article/details/78584193