JavaScript SharedArrayBuffer Object
A SharedArrayBuffer is a block of binary memory that can be shared between the main thread and web workers, so they can work on the same data at the same time.
Description
A SharedArrayBuffer is like an ArrayBuffer, but its memory can be shared between threads: when you post it to a web worker, both sides see the same bytes rather than a copy. Use Atomics to read and write it safely when several threads are involved.
For security reasons, browsers only make SharedArrayBuffer available on pages that are cross-origin isolated, which requires the Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp HTTP headers. You can check with self.crossOriginIsolated.
When several threads read and write the same memory, ordinary reads and writes can see partially updated data or lose changes, so all access to shared values that change should go through Atomics. Atomics.wait() and Atomics.notify() let workers sleep until another thread signals them, which is the building block for locks and queues.
Shared memory is mostly used by performance-critical code, such as WebAssembly applications, games and audio processing, that needs several threads working on the same data. For most applications, sending copies of data between threads with postMessage() is simpler and safe.
Creating
new SharedArrayBuffer(byteLength)Example
Browser Support
The following information will show you the current browser support for the SharedArrayBuffer object. Hover over a browser icon to see the version that first introduced support for this object.
Desktop





Tablets & Mobile





