unix高级环境编程 第二版 P328 翻译错了一个地方(第十二章 线程控制)
来源:互联网 发布:hadoop与云计算 编辑:程序博客网 时间:2024/06/05 22:38
中文版如下图:
上面那句:
- 这样其他线程试图对这个互斥量的加锁就会被堵塞
是错误的,应该是同一个线程。相当与于说,同一个线程在信号处理程序之前调用了一次getenv_r,加了一次锁,然后信号来了,又在信号处理程序中调用getenv_r,又加了一次锁。那么如果不是递归锁,就会死锁。所以必须要递归锁。
另付上英文原版为证明:
If we make getenv_r thread-safe, that doesn't mean that it is reentrant with respect to signal handlers. If we use a nonrecursive mutex, we run the risk that a thread will deadlock itself if it calls getenv_r from a signal handler.If the signal handler interrupts the thread while it is executing getenv_r, we will already be holding env_mutex locked, so another attempt to lock it will block, causing the thread to deadlock. Thus, we must use a recursive mutex to prevent other threads from changing the data structures while we look at them, and also prevent deadlocks from signal handlers. The problem is that the pthread functions are not guaranteed to be async-signal safe, so we can't use them to make another function async-signal safe.
If we make getenv_r thread-safe, that doesn't mean that it is reentrant with respect to signal handlers. If we use a nonrecursive mutex, we run the risk that a thread will deadlock itself if it calls getenv_r from a signal handler.If the signal handler interrupts the thread while it is executing getenv_r, we will already be holding env_mutex locked, so another attempt to lock it will block, causing the thread to deadlock. Thus, we must use a recursive mutex to prevent other threads from changing the data structures while we look at them, and also prevent deadlocks from signal handlers. The problem is that the pthread functions are not guaranteed to be async-signal safe, so we can't use them to make another function async-signal safe.
0 0
- unix高级环境编程 第二版 P328 翻译错了一个地方(第十二章 线程控制)
- UNIX环境高级编程第十二章 线程控制 总结
- UNIX环境高级编程学习之第十二章线程控制-以分离状态创建线程
- UNIX环境高级编程学习之第十二章线程控制-可重入(线程安全)的getenv方法
- unix高级环境编程 例子 代码实现练习 第十二章:线程控制
- UNIX环境高级编程(第12章 线程控制)
- 《UNIX环境高级编程》 第12章 线程控制 【读书笔记】
- UNIX环境高级编程-第12章- 线程控制 - 一
- UNIX环境高级编程-第12章- 线程控制 - 二
- 《UNIX环境高级编程》第12章 线程控制
- UNIX环境高级编程(十二)线程控制
- unix环境高级编程-线程控制(1)
- unix环境高级编程-线程控制(2)
- 《unix环境高级编程》第二版 第八章 进程控制 知识点
- 《unix高级环境编程》线程控制——线程属性
- 《unix高级环境编程》线程控制——线程属性
- 《Unix环境高级编程》第二版
- 《Unix环境高级编程》第二版
- OpenCV之HOG的相关函数
- sqlserver中跨服务器查询数据
- 【bzoj1934】 [Shoi2007]Vote 善意的投票
- 诚信通(b2b)信息发布5大核心技巧
- Java学习笔记 - 01
- unix高级环境编程 第二版 P328 翻译错了一个地方(第十二章 线程控制)
- dom4j解析xml文件
- Leetcode_remove-duplicates-from-sorted-array
- 黑马程序员--------------JAVA基础(二)
- 浅谈javascript函数劫持
- Java 成员变量与局部变量的区别:
- 日志
- 【PR学习笔记二】【搬砖】SVM(支持向量机)基础
- 小巧才便携 五款旅行必备移动电源推荐