linux - semaphore信号量多进程及undo标志的系统回收资源问题
大家讲道理
大家讲道理 2017-04-17 11:35:17
[Linux讨论组]

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

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

大家讲道理
大家讲道理

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

全部回复(1)
巴扎黑

Semaphore值最小为0,不可能为负数。

根据《操作系统设计与实现》(Operating Systems - Design and Implementation by Tanenbaum etc.)第三版 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.

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号