UNB/ CS/ David Bremner/ teaching/ cs2613/ books/ mdn/ Reference/ Global Objects/ Atomics/ Atomics.sub()

The Atomics.sub() static method subtracts a given value at a given position in the array and returns the old value at that position. This atomic operation guarantees that no other write happens until the modified value is written back.

Syntax

Atomics.sub(typedArray, index, value)

Parameters

Return value

The old value at the given position (typedArray[index]).

Exceptions

Examples

Using sub

const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
ta[0] = 48;

Atomics.sub(ta, 0, 12); // returns 48, the old value
Atomics.load(ta, 0); // 36

Specifications

Browser compatibility

See also