public static NamedSemaphore GetNamedSemaphore(
string name,
int maximumCount = 10,
int initialCount = -1,
bool global = true
)
Public Shared Function GetNamedSemaphore (
name As String,
Optional maximumCount As Integer = 10,
Optional initialCount As Integer = -1,
Optional global As Boolean = true
) As NamedSemaphore
public:
static NamedSemaphore^ GetNamedSemaphore(
String^ name,
int maximumCount = 10,
int initialCount = -1,
bool global = true
)
Gemstone.Threading.InterprocessLock.GetNamedSemaphore = function(name, maximumCount, initialCount, global);
This function uses a hash of the name when creating the NamedSemaphore, not the actual name - this way restrictions on the name length do not need to be a user concern. All processes needing an inter-process NamedSemaphore need to use this same function to ensure access to the same NamedSemaphore.
The name can be a string of any length (must not be empty, null or white space) and is not case-sensitive. All hashes of the name used to create the global NamedSemaphore are first converted to lower case.
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.
ArgumentNullException | Argument name cannot be empty, null or white space. |
UnauthorizedAccessException | The named semaphore exists, but the user does not have the minimum needed security access rights to use it. |