Skip to content

Instantly share code, notes, and snippets.

@nex3
Created Jul 31, 2020
Embed
What would you like to do?
const wt = require('worker_threads');
if (wt.isMainThread) {
console.log("in main");
const data = new Int32Array(new SharedArrayBuffer(4));
const worker = new wt.Worker(__filename, {
workerData: data
});
Atomics.wait(data, 0, 0);
console.log(data[0]);
} else {
Atomics.store(wt.workerData, 0, 42);
Atomics.notify(wt.workerData, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment