Atomics
A JavaScript object of functions that read and change shared memory in steps that cannot be interrupted by another thread.
In more detail
Atomics.add(view, 0, 1) always increments correctly even if two threads do it at once, which an ordinary += does not. Atomics.wait() and Atomics.notify() let threads sleep until another thread signals them.
Related terms
- SharedArrayBuffer — A block of raw memory that several threads can read and write at the same time, without copying.
- race condition — A bug whose outcome depends on the timing of two things happening at once.
- mutex — A lock that lets only one piece of code at a time run a critical section or do a particular piece of work.
Taught in
- Worker Threads: worker_threads & SharedArrayBuffer — Node.js Internals & Backend Services