ISemaphore InterfaceHazelcast .Net Client Class Library
ISemaphore is a backed-up distributed alternative to the System.Threading.Semaphore .

Namespace: Hazelcast.Core
Assembly: Hazelcast.Net (in Hazelcast.Net.dll) Version: 3.8.2
Syntax

public interface ISemaphore : IDistributedObject

The ISemaphore type exposes the following members.

Methods

  NameDescription
Public methodAcquire
Acquires a permit, if one is available and returns immediately, reducing the number of available permits by one.
Public methodAcquire(Int32)
Acquires the given number of permits, if they are available, and returns immediately, reducing the number of available permits by the given amount.
Public methodAvailablePermits
Returns the current number of permits currently available in this semaphore.
Public methodDestroy
Destroys this object cluster-wide.
(Inherited from IDistributedObject.)
Public methodDrainPermits
Acquires and returns all permits that are immediately available.
Public methodGetName
Returns the unique name for this IDistributedObject.
(Inherited from IDistributedObject.)
Public methodGetPartitionKey
Returns the key of partition this IDistributedObject is assigned to.
(Inherited from IDistributedObject.)
Public methodGetServiceName
Returns the service name for this object.
(Inherited from IDistributedObject.)
Public methodInit
Try to initialize this ISemaphore instance with given permit count
Public methodReducePermits
Shrinks the number of available permits by the indicated reduction.
Public methodRelease
Releases a permit, increasing the number of available permits by one.
Public methodRelease(Int32)
Releases the given number of permits, increasing the number of available permits by that amount.
Public methodTryAcquire
Acquires a permit, if one is available and returns immediately, with the value true, reducing the number of available permits by one.
Public methodTryAcquire(Int32)
Acquires the given number of permits, if they are available, and returns immediately, with the value true, reducing the number of available permits by the given amount.
Public methodTryAcquire(Int64, TimeUnit)
Acquires a permit from this semaphore, if one becomes available within the given waiting time and the current thread has not been interrupted.
Public methodTryAcquire(Int32, Int64, TimeUnit)
Acquires the given number of permits, if they are available and returns immediately, with the value true , reducing the number of available permits by the given amount.
Top
Remarks

ISemaphore is a cluster-wide counting semaphore. Conceptually, it maintains a set of permits. Each Acquire() blocks if necessary until a permit is available, and then takes it. Each Release() adds a permit, potentially releasing a blocking acquirer. However, no actual permit objects are used; the semaphore just keeps a count of the number available and acts accordingly.

The Hazelcast distributed semaphore implementation guarantees that threads invoking any of the acquire methods are selected to obtain permits in the order in which their invocation of those methods was processed(first-in-first-out; FIFO). Note that FIFO ordering necessarily applies to specific internal points of execution within the cluster. So, it is possible for one member to invoke acquire before another, but reach the ordering point after the other, and similarly upon return from the method.

This class also provides convenience methods to acquire and release multiple permits at a time. Beware of the increased risk of indefinite postponement when using the multiple acquire. If a single permit is released to a semaphore that is currently blocking, a thread waiting for one permit will acquire it before a thread waiting for multiple permits regardless of the call order.

  • Correct usage of a semaphore is established by programming convention in the application.
See Also

Reference