Take the 2-minute tour ×

I am using System V semaphores and want to block a process at its start and wait for another process to up the specific semaphore after it has completed its critical section.
I think that sem_op = 0, would be the proper action to do.

So I initialize the semaphore with 1.
Then at process A, that needs to be blocked I am using the sem_op = 0 in order to wait for the semaphore to became 0. At process B I am using sem_op = -1. (So this makes the semaphore.val = 0).

And the process that should be blocked prints at stdout when the other has succesfully down'ed the semaphore.

What does the wait for zero functionality actually do and how can I properly use it?

Thank you for your time!

share|improve this question
add comment

1 Answer

As per the manual, semop = 0 is the "wait-for-zero" operation. So your algorithm should work. However, it is preferable to solve these problems using the traditional P and V operators, where P means semop = -1 and V means semop = +1. So if the initial value of semaphore is 0, Process A should do a P operation and block. Process B should complete its critical section and do a V operation. As soon as Process B does a V operation, Process A's P operation would be completed and it can progress ahead.

share|improve this answer
I have managed to do it with up and down actions but I wanted to test and figure out where and when this wait for zero operation is needed. I think I found an example. –  Chris Dec 2 '12 at 15:46
add comment

Your Answer


