linux - semaphore信号量多进程及undo标志的系统回收资源问题
大家讲道理
大家讲道理 2017-04-17 11:35:17
0
1
504

1、创建semaphore信号量集(仅创建一个信号量),初始值为0
2、进程a释放掉n个信号量,进程b获取了m个信号量(n >m)均使用undo标志, 此时在进程a中获取信号量值,为n - m
3,杀掉进程a, 再次在进程b中获取信号量值,为0

问题是为什么此时的信号量值不为-m,还是说系统当前的信号量值只能为非负,才会导致这种结果?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
巴扎黑

The minimum Semaphore value is 0 and cannot be a negative number.

According to "Operating Systems - Design and Implementation by Tanenbaum etc." third edition 2.2.5 Semaphores:

The down operation on a semaphore checks to see if the value is greater than 0...If the value is 0, the process is put to sleep without completing the down for the moment...after an up on a semaphore with process sleeping on it, the semaphore will still be 0, but there will be one fewer process sleeping on it.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!