Open nerdgod opened 8 hours ago
In short: Which of the following is true (Assuming only one writing thread, 'main', which uses Atomics.notify() to inform waiting threads that there is an update to the contents of a shared SharedArrayBuffer sab
)?:
sab
is immediately accessible to reader threads once their .wait() returns 'ok'. Not just the value at their waiting index. sab
using Atomics.store() are immediately accessible to the reader once their wait() returns 'ok'the tc39 reference suggests that TypedArray.set() may be unordered, so I worry that unless I use Atomics, locks may be released before all the pages affected by the set() get written. The reference also says implementers should ensure that "Atomic operations are never rearranged with each other or with non-atomic operations.", which implies I should be able to assume (1), but I can't discern if that's true in practice.
I'm not an expert on the specifics of these classes, but whatever the TC39 says should be the case for the project. If you have evidence that suggests otherwise, that's probably a bug.
If this isn't the answer you're looking for, no worries, and someone else better informed than I may have a better response.
Node.js Version
v22.9.0
NPM Version
v10.8.3
Operating System
Windows
Subsystem
worker_threads
Description
Let's say I have a SharedArrayBuffer
sab
, and various threads have access to it, but only one thread writes to it.Reader threads map
sab
to a Uint8Arrayarr
, and they callAtomics.wait(arr,0,0)
, and wait for the writer to set that flag, before reading fromarr[1]
onward.The writer, using its own Uint8Array
arr0
mapped tosab
, callsThe question is: does
Atomics.store()
then ensure thatarr0.set
is a complete write and all threads reading from ANY part ofsab
(regardless of which portion a given TypedArray may be mapped to, upon whichAtomics.notify()
was called) have synchronized data once theirwait
returns ok?Minimal Reproduction
No response
Output
No response
Before You Submit