Zero semaphore permissions?

I'm trying to use the first answer to this question to help me with an assignment I'm working on. How does a semaphore with a resolution of 0 work? It really doesn't really matter to me. Is it easy to create an eternal wait on this semaphore? If so, how can you have a thread "escape" the semaphore while it is just waiting for a permission that it will never be given?

+3


source to share


1 answer


Again from The Little Semaphore Book, Section 2.2:

Code Listing 2.1: Semaphore initialization syntax

fred = Semaphore(1)

      

The function Semaphore

is a constructor; it creates and returns a new Semaphore. The initial value of the semaphore is passed as a parameter to the constructor.

So, the author's pseduocode 0

doesn't have a number of permissions; this is the initial value of the semaphore. What does zero mean? He clarified in the text immediately following Listing 2.1:



If the value is positive, it represents the number of threads that can be reduced without blocking. If negative, then it represents the number of threads that have blocked and are waiting. If the value is zero, it means there are no threads waiting, but if the thread tries to shrink it will block.

(accents added)

+6


source







All Articles