Node.js & Libuv•Part 3: Streams, Buffers & Core Modules (21 - 35)
Worker Thread communication.
In Simple Words:
Communicates via MessagePort using postMessage(data) and listening on parentPort.on('message', ...). For high-throughput zero-copy access, uses SharedArrayBuffer with Atomics for thread-safe synchronization.
javascript
// Zero-copy shared memory between threads:
const sab = new SharedArrayBuffer(4); // 4 bytes
const int32 = new Int32Array(sab);
// In worker thread:
Atomics.add(int32, 0, 1); // Thread-safe atomic increment