How to revoke SEM_UNDO of latest operation on semaphore?

孤街醉人 提交于 2020-01-06 08:36:32

问题


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:


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


来源:https://stackoverflow.com/questions/21057454/how-to-revoke-sem-undo-of-latest-operation-on-semaphore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!