Named and unnamed posix semaphores

Planning to use the posix semaphore to synchronize two processes. Not quite sure what to use - name or unnamed.

What are the advantages and disadvantages of each? How can I decide what to use? In which situations is preferable to others?

Thanks.

+4
source share
1 answer

If the two processes are not related to each other, you should use a named semaphore. If two processes are connected (i.e. Forked), or if you just use a semaphore between threads, you should use unnamed.

The benefits of the unnamed are that you do not need to keep track of names and any permissions or disable them. And unnamed semaphores can be used as a simple global variable (or on the heap) in the case when they are distributed between threads of the same process, or placed in shared memory, which will be inherited by children in the case of a bifurcated process.

+2
source

All Articles