Skip to content

Instantly share code, notes, and snippets.

@nex3
Created July 31, 2020 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nex3/1a6d96eadfe32c106917cace7c376cc8 to your computer and use it in GitHub Desktop.
Save nex3/1a6d96eadfe32c106917cace7c376cc8 to your computer and use it in GitHub Desktop.
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