JS Built-ins
Atomicssubbeginner

Atomics.sub returns old value

πŸ“– Usage Example
const i32 = new Int32Array(new SharedArrayBuffer(4))
Atomics.store(i32, 0, 10)
Atomics.sub(i32, 0, 3)  // β†’ 10 (old value)
Atomics.load(i32, 0)   // β†’ 7

Atomics.sub() atomically subtracts a value, returning the old value before subtraction.

Use Atomics.sub to get the old value at an index before subtracting.

πŸ’‘ Hints (1)
  • β€’ Use Atomics.sub(typedArray, index, value)