SEMOP:当减少一组信号量都在减少或一次它在第一次失败阻止? [英] Semop: When decreasing a set of semaphores are all decremented at once or does it block on first failure?

查看:188
本文介绍了SEMOP:当减少一组信号量都在减少或一次它在第一次失败阻止?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,如果我有一个的信号灯设置 semid的 num_of_sems 信号灯和一个 sembuf * deleter_searchers_down

So if I have a semaphore set semid with num_of_sems semaphores and a 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,并继续其他进程跌宕之后,调用特定的信号?

The call to semop will attempt to lower all semaphores in the set at once or will it block once it attempts to lower the first semaphore that is 0 and continue after some other process ups that particular semaphore?

推荐答案

没有更新发生,直到所有的更新可以作为一个单元进行。

No updates happen until all updates can proceed as a unit.

在POSIX规范可能是这点更清晰,虽然它说,执行semop 是原子的。

The POSIX specification could be clearer about this point, although it does say that semop is atomic.

在Linux中,执行semop(3) glibc中约一个简单的包装执行semop(2)。反过来执行semop(2)手册页说:

On Linux, semop(3) in glibc is a simple wrapper around semop(2). The semop(2) manpage in turn says

集包含在的SOP操作中的排列顺序原子执行的,也就是说,操作被执行或者作为一个完整的单元,或根本没有。

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)联机帮助页更清楚:

The HP-UX semop(2) manpage is even clearer:

信号灯
        数组操作是在没有信号灯操作原子
        直到所有的信号量阻塞的条件进行
        数组已被删除。

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.

这篇关于SEMOP:当减少一组信号量都在减少或一次它在第一次失败阻止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆