Create a new ReentrantLock instance. The given Int32Array should be based on a SharedArrayBuffer. Multiple ReentrantLock instances initialized with the same SharedArrayBuffer are grouped.
A TypedArray used to store whether or not any instance inside a group of ReentrantLock instances is locked. It has to have a length of one, and it has to be based on a SharedArrayBuffer.
The underlying @mogoe1/semaphore used by this lock.
SharedArrayBuffer used by this ReentrantLocks group.
Whether or not the instance is locked.
Locks this ReentrantLock instance and increments holdCount by one. Blocks until this instance is locked and no other instance inside the group is locked.
If Atomics.wait is not availabe (eg. on the main thread) use lockAsync() instead.
False if this instance was already locked prior to the function call. True otherwise.
Locks this ReentrantLock instance and increments holdCount by one. Immediately returns a promise that resolves once this instance is locked and no other instance inside the group is locked.
A promise that resolves to false if the instance was already locked prior to the function call. Otherwise it resolves to true.
True if tis instances is still locked (holdCount > 0). False otherwise.
Creates a new SharedArrayBuffer and a new ReentrantLock instance based on the created buffer.
The new ReentrantLock instance.
Generated using TypeDoc
A ReentrantLock can be used to synchronize async code and/or threads (WebWorkers). Multiple ReentrantLock instances can be grouped, and only one instance at a time can be locked.
An instance can be locked by calling lock() on the instance. The call blocks until no other instance inside the group is locked and increments holdCount by one. After the call returns, the instance is guaranteed to be the only one inside the group that is locked. Since lock() is a blocking operation, it is not available on the main thread. See lockAsync() for an alternative.
To unlock an instance, unlock() can be called on the instance. The invocation decrements holdCount of the instance by one if holdCount is greater than 0. The instance is unlocked if holdCount reaches zero during the invocation.
Multiple ReentrantLock instances can be grouped by providing TypedArray instances based on the same SharedArrayBuffer instance to the ReentrantLock constructor on creation.
This implementation is based on @mogoe1/semaphore and uses SharedArrayBuffers and Atomics for synchronization.