首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

linux多线程编程的两个知识点解决思路

2012-09-21 
linux多线程编程的两个知识点对pthread_cleanup_push和pthread_cleanup_pop不怎么理解,大虾们帮我解释具体

linux多线程编程的两个知识点
对pthread_cleanup_push和pthread_cleanup_pop不怎么理解,大虾们帮我解释具体解释一下,如果能有个简单的例子就更好了!

[解决办法]
记错了,,pthread_kill是发送信号的,,
应该是pthread_cancel.

int pthread_cancel(pthread_t thread);

When a cancellation requested is acted on, the following steps occur
for thread (in this order):

1. Cancellation clean-up handlers are popped (in the reverse of the
order in which they were pushed) and called. (See
pthread_cleanup_push(3).)

2. Thread-specific data destructors are called, in an unspecified
order. (See pthread_key_create(3).)

3. The thread is terminated. (See pthread_exit(3).)

[解决办法]

探讨

记错了,,pthread_kill是发送信号的,,
应该是pthread_cancel.

int pthread_cancel(pthread_t thread);

When a cancellation requested is acted on, the following steps occur
for thread (in this order):
……

[解决办法]
用用就知道了, 你去看看头文件也能明白, 它要求用户必须成对使用, 因为这是两个宏, 第一个宏是{结尾,第二个宏是}结尾, 配对使用保证程序在花括号中执行时意外退出可以给用户一个清理的机会.

比如:

{
{ 执行到这个push出错了,那么堆里就一个{,于是执行它对应的}清理函数。
}
}

热点排行