In reply to Robert.Lanier:
That question is difficult to answer without more details. A semaphore is a very low-level construct and it’s your responsibility to manage the keys correctly. There could be many simpler alternatives depending on what you are trying to accomplish.