Mutex Class
Package: @esfx/threading-mutex
Declaration
export declare class Mutex implements Lockable, Disposable
Constructors
constructor(initiallyOwned)
Constructs a new instance of the Mutex
class
Declaration
constructor(initiallyOwned?: boolean);
Parameters
- initiallyOwned
- boolean
constructor(buffer, byteOffset)
Constructs a new instance of the Mutex
class
Declaration
constructor(buffer: SharedArrayBuffer, byteOffset?: number);
Parameters
- buffer
- SharedArrayBuffer
- byteOffset
- number
Properties
buffer
Gets the SharedArrayBuffer
for this mutex.
Declaration
get buffer(): SharedArrayBuffer;
Property Value
byteLength
Gets the number of bytes occupied by this mutex in its buffer.
Declaration
get byteLength(): number;
Property Value
byteOffset
Gets the byte offset of this mutex in its buffer.
Declaration
get byteOffset(): number;
Property Value
isLocked
Gets a value indicating whether the mutex is currently locked.
Declaration
get isLocked(): boolean;
Property Value
ownsLock
Gets a value indicating whether this instance of the mutex owns the lock.
Declaration
get ownsLock(): boolean;
Property Value
SIZE
Declaration
static readonly SIZE = 4;
Methods
[Disposable.dispose]()
Releases the lock on the mutex (if this mutex owns the lock) and releases all resources for this mutex.
Declaration
[Disposable.dispose](): void;
Returns
[Lockable.lock](ms)
Declaration
[Lockable.lock](ms?: number): boolean;
Parameters
- ms
- number
Returns
[Lockable.tryLock]()
Declaration
[Lockable.tryLock](): boolean;
Returns
[Lockable.unlock]()
Declaration
[Lockable.unlock](): boolean;
Returns
close()
Releases the lock on the mutex (if this mutex owns the lock) and releases all resources for this mutex.
Declaration
close(): void;
Returns
lock(ms)
Blocks the current Agent
until it can acquire a lock on the mutex.
Declaration
lock(ms?: number): boolean;
Parameters
Returns
true
if the lock was acquired within the provided timeout period; otherwise, false
.
tryLock()
Attempts to acquire a lock on the mutex without blocking the current Agent
.
Declaration
tryLock(): boolean;
Returns
true
if the lock was acquired successfully; otherwise, false
.
unlock()
Releases the lock on the mutex allowing the next waiter to take the lock.
Declaration
unlock(): boolean;
Returns
true
if the lock was released successfully; otherwise, false
.