How to revoke SEM_UNDO of latest operation on sema

2019-09-08 23:12发布

My problem: A,B - semaphores.

Process is loop:

  1. waits for A >= 1, decrements A
  2. does some computation
  3. increments B.
  4. back to 1.

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

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.?

1条回答
叼着烟拽天下
2楼-- · 2019-09-08 23:32

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

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 with SEM_UNDO
  2. +x without SEM_UNDO
查看更多
登录 后发表回答