You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow atomic operations on unshared memories (#147)
As discussed in the CG on November 12, 2019 and in #144. Specifically,
all atomic accesses are now allowed to validate and execute normally
on unshared memories and wait operations trap when used with unshared
memories.
The PR updates Overview.md and makes a best-effort
attempt at updating the spec, making no changes when there is
already a TODO for updating spec text. It also adds new TODO comments
to the reference interpreter where changes will have to be made.
Copy file name to clipboardExpand all lines: proposals/threads/Overview.md
+19-17
Original file line number
Diff line number
Diff line change
@@ -228,9 +228,8 @@ This has been separated into
228
228
## Atomic Memory Accesses
229
229
230
230
Atomic memory accesses are separated into three categories, load/store,
231
-
read-modify-write, and compare-exchange. All atomic memory accesses require a
232
-
shared linear memory. Attempting to use atomic access operators on non-shared
233
-
linear memory is a validation error.
231
+
read-modify-write, and compare-exchange. All atomic memory accesses can be
232
+
performed on both shared and unshared linear memories.
234
233
235
234
Currently all atomic memory access instructions are [sequentially consistent][].
236
235
Instructions with other memory orderings may be provided in the future.
@@ -340,12 +339,12 @@ has any other value than the natural alignment for that access size.
340
339
## Wait and Notify operators
341
340
342
341
The notify and wait operators are optimizations over busy-waiting for a value
343
-
to change. It is a validation error to use these operators on non-shared linear
344
-
memory. The operators have sequentially consistent ordering.
342
+
to change. The operators have sequentially consistent ordering.
345
343
346
344
Both notify and wait operators trap if the effective address of either operator
347
-
is misaligned or out-of-bounds. The wait operators require an alignment of
348
-
their memory access size. The notify operator requires an alignment of 32 bits.
345
+
is misaligned or out-of-bounds. Wait operators additionally trap if used on an
346
+
unshared linear memory. The wait operators require an alignment of their memory
347
+
access size. The notify operator requires an alignment of 32 bits.
349
348
350
349
For the web embedding, the agent can also be suspended or woken via the
351
350
[`Atomics.wait`][] and [`Atomics.notify`][] functions respectively. An agent
@@ -373,14 +372,15 @@ and a relative timeout in nanoseconds as an `i64`. The return value is `0`,
373
372
|`1`| "not-equal", the loaded value did not match the expected value |
374
373
|`2`| "timed-out", not woken before timeout expired |
375
374
376
-
The wait operation begins by performing an atomic load from the given address.
377
-
If the loaded value is not equal to the expected value, the operator returns 1
378
-
("not-equal"). If the values are equal, the agent is suspended. If the agent
379
-
is woken, the wait operator returns 0 ("ok"). If the timeout expires before
380
-
another agent notifies this one, this operator returns 2 ("timed-out"). Note that
381
-
when the agent is suspended, it will not be [spuriously woken](https://en.wikipedia.org/wiki/Spurious_wakeup).
382
-
The agent is only woken by `atomic.notify` (or [`Atomics.notify`][] in the web
383
-
embedding).
375
+
If the linear memory is unshared, the wait operation traps. Otherwise, the wait
376
+
operation begins by performing an atomic load from the given address. If the
377
+
loaded value is not equal to the expected value, the operator returns 1
378
+
("not-equal"). If the values are equal, the agent is suspended. If the agent is
379
+
woken, the wait operator returns 0 ("ok"). If the timeout expires before another
380
+
agent notifies this one, this operator returns 2 ("timed-out"). Note that when
381
+
the agent is suspended, it will not be [spuriously
382
+
woken](https://en.wikipedia.org/wiki/Spurious_wakeup). The agent is only woken
383
+
by `atomic.notify` (or [`Atomics.notify`][] in the web embedding).
384
384
385
385
When an agent is suspended, if the number of waiters (including this one) is
386
386
equal to 2<sup>32</sup>, then trap.
@@ -424,7 +424,9 @@ no `Int64Array` type, and an ECMAScript `Number` cannot represent all values of
424
424
The notify operator takes two operands: an address operand and a count as an
425
425
unsigned `i32`. The operation will notify as many waiters as are waiting on the
426
426
same effective address, up to the maximum as specified by `count`. The operator
427
-
returns the number of waiters that were woken as an unsigned `i32`.
427
+
returns the number of waiters that were woken as an unsigned `i32`. Note that if
428
+
the notify operator is used with an unshared linear memory, the number of
429
+
waiters will always be zero.
428
430
429
431
*`atomic.notify`: notify `count` threads waiting on the given address via `i32.atomic.wait` or `i64.atomic.wait`
430
432
@@ -441,7 +443,7 @@ For the web embedding, `atomic.notify` is equivalent in behavior to executing th
441
443
442
444
The fence operator, `atomic.fence`, takes no operands, and returns nothing. It is intended to preserve the synchronization guarantees of the [fence operators of higher-level languages](https://en.cppreference.com/w/cpp/atomic/atomic_thread_fence).
443
445
444
-
Unlike other atomic operators, `atomic.fence` does not target a particular linear memory. It may occur in modules which declare no memory, or a non-shared memory, without causing a validation error.
446
+
Unlike other atomic operators, `atomic.fence` does not target a particular linear memory. It may occur in modules which declare no memory without causing a validation error.
0 commit comments