Node.js - Worker Threads
You want to safely increment a shared counter in a Node.js worker thread using
SharedArrayBuffer. Which code snippet correctly increments the counter without race conditions?
// Shared buffer and typed array
const sab = new SharedArrayBuffer(4);
const counter = new Int32Array(sab);
counter[0] = 0;
// Increment function
function increment() {
// Which line correctly increments?
}