LogoPear Docs
ReferencesBareModules

bare-atomics

Native synchronization primitives for JavaScript

stable

bare-atomics — Native synchronization primitives for JavaScript. It is a native addon and requires Bare >=1.2.0.

npm i bare-atomics

API

Mutex

new Mutex(opts?: MutexOptions)

Source

Parameters

ParameterTypeDefaultDescription
opts?MutexOptionsOptions; set recursive: true to let the owning thread lock the mutex more than once (default false). May also carry an existing handle to wrap.

Mutex.destroy(): void

Source

Throws

  • The mutex is still held.

Mutex.handle: SharedArrayBuffer

Source

A SharedArrayBuffer with the underlying mutex handle.

held: boolean

Source

Whether or not the current thread currently holds the mutex.

lock(): void

Source

Throws

  • The mutex is already held and was not created with recursive: true.

Mutex.from(handle: SharedArrayBuffer, opts?: MutexOptions): Mutex

Source

Create a Mutex from an existing handle; options are the same as new Mutex().

Parameters

ParameterTypeDefaultDescription
handleSharedArrayBufferA SharedArrayBuffer holding an existing mutex, as exposed by Mutex.handle.
opts?MutexOptionsOptions, the same as new Mutex().

Returns Mutex — A Mutex sharing the underlying handle.

recursive: boolean

Source

tryLock(): boolean

Source

Throws

  • The mutex is already held and was not created with recursive: true.

unlock(): void

Source

Throws

  • The mutex is not currently held.

Semaphore

new Semaphore(value: any)

Source

Parameters

ParameterTypeDefaultDescription
valueanyThe initial value (permit count) of the semaphore.

Semaphore.destroy(): void

Source

Semaphore.handle: SharedArrayBuffer

Source

A SharedArrayBuffer with the underlying mutex handle.

post(): void

Source

Semaphore.from(handle: SharedArrayBuffer): Semaphore

Source

Parameters

ParameterTypeDefaultDescription
handleSharedArrayBufferA SharedArrayBuffer holding an existing semaphore, as exposed by Semaphore.handle.

Returns Semaphore — A Semaphore sharing the underlying handle.

tryWait(): boolean

Source

wait(): void

Source

Condition

broadcast(): void

Source

Condition.from(handle: SharedArrayBuffer): Condition

Source

Parameters

ParameterTypeDefaultDescription
handleSharedArrayBufferA SharedArrayBuffer holding an existing condition variable, as exposed by Condition.handle.

Returns Condition — A Condition sharing the underlying handle.

Condition.destroy(): void

Source

Condition.handle: SharedArrayBuffer

Source

A SharedArrayBuffer with the underlying mutex handle.

signal(): void

Source

Condition.wait(): boolean

Source

Throws

  • The associated mutex is not held by the current thread.

Barrier

new Barrier(count: number)

Source

Parameters

ParameterTypeDefaultDescription
countnumberThe number of threads that must reach the barrier (call wait()) before they are all released together.

Barrier.from(handle: SharedArrayBuffer): Barrier

Source

Parameters

ParameterTypeDefaultDescription
handleSharedArrayBufferA SharedArrayBuffer holding an existing barrier, as exposed by Barrier.handle.

Returns Barrier — A Barrier sharing the underlying handle.

Barrier.destroy(): void

Source

Barrier.handle: SharedArrayBuffer

Source

A SharedArrayBuffer with the underlying mutex handle.

Barrier.wait(): boolean

Source

Types

MutexOptions

interface MutexOptions {
  recursive?: boolean
}
Source

See also

On this page