gpt4 book ai didi

c - semop : When decreasing a set of semaphores are all decremented at once or does it block on first failure?

转载 作者:太空狗 更新时间:2023-10-29 15:01:07 25 4
gpt4 key购买 nike

因此,如果我有一个信号量集 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com