Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardNodeJSSharedArrayBuffer and AtomicsSingle-choice MCQ

A worker spins in a tight loop polling a flag in a SharedArrayBuffer-backed Int32Array using a plain `arr[0] === 1` read, while another thread does a plain `arr[0] = 1`. Why is this potentially broken even on a coherent x86 cache, and what fixes it?

// shared: const arr = new Int32Array(sab); // thread A: while (arr[0] === 0) { /* spin */ } console.log('saw it'); // thread B (later): arr[0] = 1;