- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
因此,如果我有一个信号量集 semid
,带有num_of_sems
个信号量和一个sembuf *deleter_searchers_down
struct sembuf *deleter_searchers_down
= malloc(sizeof (*deleter_searchers_down) * num_of_sems);
for (i = 0; i < num_of_sems; ++i) {
(deleter_searchers_down + i)->sem_op = -1;
(deleter_searchers_down + i)->sem_num = i;
(deleter_searchers_down + i)->sem_flg = SEM_UNDO;
}
semop(semid, deleter_searchers_down, num_of_sems);
对 semop 的调用将尝试立即降低集合中的所有信号量,或者它是否会在尝试降低第一个为 0 的信号量并在其他进程升高该特定信号量后继续进行时阻塞?
最佳答案
在所有更新可以作为一个单元进行之前,不会发生更新。
POSIX 规范在这一点上可能更清楚,尽管它确实说 semop
是原子的。
在 Linux 上,glibc 中的 semop(3)
是 semop(2)
的简单包装器。 semop(2)
手册页反过来说
The set of operations contained in
sops
is performed in array order, and atomically, that is, the operations are performed either as a complete unit, or not at all.
HP-UX semop(2)
联机帮助页更加清晰:
Semaphore array operations are atomic in that none of the semaphore operations are performed until blocking conditions on all of the semaphores in the array have been removed.
关于c - semop : When decreasing a set of semaphores are all decremented at once or does it block on first failure?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10206501/
我是一名优秀的程序员,十分优秀!