l0.DependencyControl.NamedSemaphore¶
NamedSemaphore ¶
A non-reentrant binary semaphore identified by a name. Usable as a per-process or cross-process lock primitive.
Constructor ¶
Gets a handle to the named semaphore for the given token, creating it if it doesn't exist. this instance is collected — that would break a name another holder still owns). Use true for process-private names so a reused PID can't inherit a stale semaphore. Use false for cross-process usage to prevent an exiting process from removing a name others still hold. No effect on Windows, where names are cleaned up automatically when the last handle closes.
| param | type | description |
|---|---|---|
| token | string |
A name token restricted to [A-Za-z0-9_]. |
| unlinkOnClose? | boolean |
POSIX-only: remove the OS name when this Lua state tears down (not when |
Instance methods¶
tryLock ¶
Attempts to acquire without blocking.
Returns:
acquiredboolean— True if the semaphore was acquired.
lock ¶
Blocks until the semaphore is acquired.
Returns:
issuedboolean— True if a wait was issued (false only when unavailable).
unlock ¶
Releases one unit of the semaphore. Safe to call only by the current holder.
Returns:
issuedboolean— True if a release was issued.
Fields¶
| field | type | description |
|---|---|---|
| isAvailable | boolean |
|
| pid | integer |