MutexList
Create a managed object collection backed by a node Buffer
and share the data across threads.
Usage
; ;; // bytes ; // this is the critical area SharedArrayBuffer;// this is the data SharedArrayBuffer; worker.postMessage;
Inside a Worker, do the following things:
;; // bytes ;parentPort.on"message",;
API
constructor
The constructor creates a mutex list
constructor count?: number, // The number of records in the mutex list size?: number, // how many bytes per record criticalBuffer?: SharedArrayBuffer, // the critical section buffer dataBuffer?: SharedArrayBuffer, // the data section buffer;
lock
Lock a record by it's index. This method stops the current thread from executing synchronously using Atomic.wait()
and Atomic.compareExchange()
. This method returns a node Buffer
object once the record is locked.
unlock
Unlock a record by it's index. This method notifies a single thread that has called lock()
, and frees the record using Atomic.notify()
and Atomic.compareExchange()
. This method returns void
.