diff --git a/benchmark/worker/atomics-wait.js b/benchmark/worker/atomics-wait.js new file mode 100644 index 00000000000..a771b181373 --- /dev/null +++ b/benchmark/worker/atomics-wait.js @@ -0,0 +1,15 @@ +'use strict'; +/* global SharedArrayBuffer */ + +const common = require('../common.js'); +const bench = common.createBenchmark(main, { + n: [1e7] +}); + +function main({ n }) { + const i32arr = new Int32Array(new SharedArrayBuffer(4)); + bench.start(); + for (let i = 0; i < n; i++) + Atomics.wait(i32arr, 0, 1); // Will return immediately. + bench.end(n); +} diff --git a/doc/api/cli.md b/doc/api/cli.md index e6310b279f4..82e2f674a8a 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -816,6 +816,33 @@ added: v12.0.0 Set default [`tls.DEFAULT_MIN_VERSION`][] to 'TLSv1.3'. Use to disable support for TLSv1.2, which is not as secure as TLSv1.3. +### `--trace-atomics-wait` + + +Print short summaries of calls to [`Atomics.wait()`][] to stderr. +The output could look like this: + +```text +(node:15701) [Thread 0] Atomics.wait(
+ 0, 1, inf) started +(node:15701) [Thread 0] Atomics.wait( + 0, 1, inf) did not wait because the values mismatched +(node:15701) [Thread 0] Atomics.wait( + 0, 0, 10) started +(node:15701) [Thread 0] Atomics.wait( + 0, 0, 10) timed out +(node:15701) [Thread 0] Atomics.wait( + 4, 0, inf) started +(node:15701) [Thread 1] Atomics.wait( + 4, -1, inf) started +(node:15701) [Thread 0] Atomics.wait( + 4, 0, inf) was woken up by another thread +(node:15701) [Thread 1] Atomics.wait( + 4, -1, inf) was woken up by another thread +``` + +The fields here correspond to: + +* The thread id as given by [`worker_threads.threadId`][] +* The base address of the `SharedArrayBuffer` in question, as well as the + byte offset corresponding to the index passed to `Atomics.wait()` +* The expected value that was passed to `Atomics.wait()` +* The timeout passed to `Atomics.wait` + ### `--trace-deprecation`