Reputation: 53
Planning to use a posix semaphore to sync 2 processes. Not quite sure which to use - named or unnamed.
What are the advantages and disadvantages of each? How do I decide which to use? On which situations, is one preferable over the other?
Thanks.
Upvotes: 5
Views: 1183
Reputation: 27552
If the two processes are unrelated you should use a named semaphore. If the two process are related (i.e. forked) or if you are just using the semaphore between threads you should use unnamed.
The advantages of unnamed are that you don't have to keep track of the names and any permissions nor unlink them. And unnamed semaphores can be use as a simple global variable (or on the heap) in the case where they are being shared between threads of the same process, or put in shared memory which will be inherited by the children in the case of a forked process.
Upvotes: 3