NamedSemaphore Class

Represents a cross-platform, interprocess named semaphore, which limits the number of threads that can concurrently access a resource or a pool of resources.

Definition

Namespace: Gemstone.Threading
Assembly: Gemstone.Threading (in Gemstone.Threading.dll) Version: 1.0.110 -- Release Build+13c244059615c58a533059438f38d7e59ef0c2ea
public class NamedSemaphore : WaitHandle
Inheritance
Object    MarshalByRefObject    WaitHandle    NamedSemaphore

Remarks

A NamedSemaphore is a synchronization object that can be utilized across multiple processes.

On POSIX systems, the NamedSemaphore exhibits kernel persistence, meaning instances will remain active beyond the lifespan of the creating process. Named semaphores must be explicitly removed by invoking Unlink when they are no longer needed. Kernel persistence necessitates careful design consideration regarding the responsibility for invoking Unlink. Since the common use case for named semaphores is across multiple applications, it is advisable for the last exiting process to handle the cleanup. In cases where an application may crash before calling Unlink, the semaphore persists in the system, potentially leading to resource leakage. Implementations should include strategies to address and mitigate this risk.

Constructors

NamedSemaphore(Int32, Int32, String) Initializes a new instance of the NamedSemaphore class, specifying the initial number of entries, the maximum number of concurrent entries, and the name of a system semaphore object.
NamedSemaphore(Int32, Int32, String, Boolean) Initializes a new instance of the NamedSemaphore class, specifying the initial number of entries, the maximum number of concurrent entries, the name of a system semaphore object, and specifying a variable that receives a value indicating whether a new system semaphore was created.

Properties

HandleGets or sets the native operating system handle.
(Inherited from WaitHandle)
Obsolete.
Name Gets the name of the NamedSemaphore.
SafeWaitHandle Gets or sets the native operating system handle.

Methods

Close Releases all resources held by the current NamedSemaphore.
(Overrides WaitHandleClose)
DisposeReleases all resources used by the current instance of the WaitHandle class.
(Inherited from WaitHandle)
Dispose(Boolean) When overridden in a derived class, releases the unmanaged resources used by the NamedSemaphore, and optionally releases the managed resources.
(Overrides WaitHandleDispose(Boolean))
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Obsolete.
GetTypeGets the Type of the current instance.
(Inherited from Object)
InitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Obsolete.
MemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
MemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject)
OpenExisting Opens an existing named semaphore.
Release Exits the semaphore and returns the previous count.
Release(Int32) Exits the semaphore a specified number of times and returns the previous count.
ToStringReturns a string that represents the current object.
(Inherited from Object)
TryOpenExisting Opens the specified named semaphore, if it already exists, and returns a value that indicates whether the operation succeeded.
Unlink Removes a named semaphore.
Unlink(String) Removes a named semaphore.
WaitOne Blocks the current thread until the current NamedSemaphore receives a signal.
(Overrides WaitHandleWaitOne)
WaitOne(Int32) Blocks the current thread until the current instance receives a signal, using a 32-bit signed integer to specify the time interval in milliseconds.
(Overrides WaitHandleWaitOne(Int32))
WaitOne(TimeSpan) Blocks the current thread until the current instance receives a signal, using a TimeSpan to specify the time interval.
(Overrides WaitHandleWaitOne(TimeSpan))
WaitOne(Int32, Boolean) Blocks the current thread until the current NamedSemaphore receives a signal, using a 32-bit signed integer to specify the time interval and specifying whether to exit the synchronization domain before the wait.
(Overrides WaitHandleWaitOne(Int32, Boolean))
WaitOne(TimeSpan, Boolean) Blocks the current thread until the current instance receives a signal, using a TimeSpan to specify the time interval and specifying whether to exit the synchronization domain before the wait.
(Overrides WaitHandleWaitOne(TimeSpan, Boolean))

See Also