同步锁--摘自《unix网络编程》第二卷

关于互斥:
When a mutex is shared between processes, there is always a chance that the process can terminate (perhaps involuntarily) while holding the mutex lock. There is no way to have the system automatically release held locks upon process termination. We will see that read-write locks and Posix semaphores share this property. The only type of synchronization locks that the kernel always cleans up automatically upon process termination is fcntl record locks(Chapter 9). When using System V semaphores, the application chooses whether a semaphore lock is automatically cleaned up or not by the kernel upon process termination (the SEM_UNDO feature that we talk about in Section 11.3).

 

书中还提到:
即使一个进程终止时系统自动释放某个锁,那也可能解决不了问题。
该锁保护某个临界区很可能是为了在执行该临界区代码期间更新某个数据。
如果该进程在执行该临界区的中途终止,该数据处于什么状态呢?该数据处于不一致状态的可能性很大。
如果内核仅仅在进程终止时自动解锁的话,通常于事无补。
需要小心使用。

 

关于Posix有名信号灯:
“关闭一个信号灯并没有将它从系统中删除。这就是说,
Posix有名信号灯至少是随内核持续的:即使当前没有进程打开着某个信号灯,它的值仍然保持。”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值