public static NamedSemaphore GetNamedSemaphore(
bool perUser,
int maximumCount = 10,
int initialCount = -1
)
Public Shared Function GetNamedSemaphore (
perUser As Boolean,
Optional maximumCount As Integer = 10,
Optional initialCount As Integer = -1
) As NamedSemaphore
public:
static NamedSemaphore^ GetNamedSemaphore(
bool perUser,
int maximumCount = 10,
int initialCount = -1
)
Gemstone.Threading.InterprocessLock.GetNamedSemaphore = function(perUser, maximumCount, initialCount);
This function uses a hash of the assembly's GUID when creating the NamedSemaphore, if it is available. If it is not available, it uses a hash of the simple name of the assembly. Although the name is hashed to help guarantee uniqueness, it is still entirely possible that another application may use that name with the same hashing algorithm to generate its NamedSemaphore name. Therefore, it is best to ensure that the GuidAttribute is defined in the AssemblyInfo of your application.
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.
UnauthorizedAccessException | The named semaphore exists, but the user does not have the minimum needed security access rights to use it. |