4

I am dealing with unrelated processes synchronization. For unrelated processes, Named semaphores are necessary. We can't handle unrelated process with Unnamed Semaphore as mentioned here StackOverFlow. Now, if we want to use Named semaphore (counting semaphore) as a binary semaphore, then what is the procedure. I know that we can make Unnamed Semaphore to binary semaphore as mentioned here StackOverFlow . And if we want to synchronize threads by binary semaphores, then pthread_mutex are available. May you please suggest how to use named semaphore as binary semaphore or Is there any other methods to synchronize unrelated process as binary semaphores. Thanks in advance.

6
  • 1
    It's a bit unclear what you're asking, but if I understand you correctly then the answer is simply "never increase the semaphore's value above one". You can achieve that by initializing the semaphore to value 1, and by ensuring that the value is only incremented by a thread that has previously decremented it successfully, with exactly one increment following each decrement. Commented Aug 22, 2015 at 18:05
  • thanks, but can you elaborate it. Suppose I have multiple processes then to increment or decrement semaphore value I have to use common thread shared between all process. How it is implemented? Commented Aug 22, 2015 at 19:04
  • No, you are entirely missing the point of a semaphore. Any thread of any process can increment it or try to decrement it. It is thread-safe to do so, else the semaphore couldn't do its job. Commented Aug 23, 2015 at 0:29
  • 1st comment: "ensuring that the value is only incremented by a thread that has previously decremented" 2nd comment: "Any thread of any process can increment it or try to decrement it." I have multiple processes and they have to share. please explain Commented Aug 24, 2015 at 16:09
  • "Two processes can operate on the same named semaphore by passing the same name to sem_open(3)." (Linux manual page sem_overview(7)). Moreover, POSIX semaphores are thread-safe within each process. These characteristics are required for them to serve their purpose. Commented Aug 25, 2015 at 0:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.