如何撤消对信号量的最新操作SEM_UNDO? [英] How to revoke SEM_UNDO of latest operation on semaphore?

查看:168
本文介绍了如何撤消对信号量的最新操作SEM_UNDO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题: A,B-信号灯.

My problem: A,B - semaphores.

过程是循环的:

  1. 等待A> = 1,递减A
  2. 进行一些计算
  3. 增加B.
  4. 回到1.

目标:进程终止后,我需要将A的减量等于B的增量.

Goal: After process terminates i need decrements of A be equal to increments of B.

所以我知道我将在1中添加标志SEM_UNDO,但是它将撤消该进程对A所做的每个减量.当进程达到4.时,如何从1.撤消/撤消SEM_UNDO?

So i figure out i will add flag SEM_UNDO in 1. but it undos every DEcrement ever made to A by that process. How to revoke / undo SEM_UNDO from 1. when process reaches 4.?

推荐答案

好的,当我想到将问题撤消" SEM_UNDO而不是撤消"该问题时,我感到很高兴.

ok, i was enlightened when thinking about problem as "undoing" SEM_UNDO rather then "revoking" it.

在使用SEM_UNDO的+ x操作调用semop()之后,您可以稍后通过以下两个操作再次调用 semop()来撤消该SEM_UNDO:

after calling semop() with operation +x with SEM_UNDO, you can later undo that SEM_UNDO by calling semop() again with two operations:

  1. -x与SEM_UNDO
  2. + x,不带SEM_UNDO

这篇关于如何撤消对信号量的最新操作SEM_UNDO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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