Semaphore

A semaphore maintains a fixed number of threads in executions or allow to acquire the lock.,A semaphore maintains a fixed number of threads in executions or allow to acquire the lock.,
Below method will get the lock of semaphore within semaphore.availablePermits()

If there are more that fixed threads, it will wait to acquire/get the semaphore lock untile it has semaphore.availablepermits() greater than ‘0’.
A semaphore initialized to one, has only one permit available is a mutual exclusion lock, which we can say as “mutex“.
This is more commonly known as a binary semaphore, as it has 2 states, zero permit and one permit, and lock can be released from other threads.

Result:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *