Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Overview] Change wake to use unsigned semantics #110

Merged
merged 3 commits into from
Nov 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions proposals/threads/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,12 @@ when the agent is suspended, it will not be [spuriously woken](https://en.wikipe
The agent is only woken by `atomic.wake` (or [`Atomics.wake`][] in the web
embedding).

When an agent is suspended, if the number of waiters (including this one) is
equal to 2<sup>32</sup>, then trap.

* `i32.atomic.wait`: load i32 value, compare to expected (as `i32`), and wait for wake at same address
* `i64.atomic.wait`: load i64 value, compare to expected (as `i64`), and wait for wake at same address

For the web embedding, `i32.atomic.wait` is equivalent in behavior to executing the following:

1. Let `memory` be a `WebAssembly.Memory` object for this module.
Expand All @@ -394,7 +397,7 @@ For the web embedding, `i32.atomic.wait` is equivalent in behavior to executing
as described above.
1. Return an `i32` value as described in the above table:
("ok" -> `0`, "not-equal" -> `1`, "timed-out" -> `2`).

`i64.atomic.wait` has no equivalent in ECMAScript as it is currently specified, as there is
no `Int64Array` type, and an ECMAScript `Number` cannot represent all values of a
64-bit integer. That said, the behavior can be approximated as follows:
Expand All @@ -418,26 +421,19 @@ no `Int64Array` type, and an ECMAScript `Number` cannot represent all values of
### Wake

The wake operator takes two operands: an address operand and a wake count as an
`i32`. The operation will wake as many waiters as are waiting on the same
effective address, up to the maximum as specified by `wake count`. The operator
returns the number of waiters that were woken as an `i32`.

`wake count` value | Behavior |
| ---- | ---- |
| `wake count` < 0 | Wake all waiters |
| `wake count` == 0 | Wake no waiters |
| `wake count` > 0 | Wake min(`wake count`, `num waiters`) waiters |
unsigned `i32`. The operation will wake as many waiters as are waiting on the
same effective address, up to the maximum as specified by `wake count`. The
operator returns the number of waiters that were woken as an unsigned `i32`.

* `atomic.wake`: wake up `wake count` threads waiting on the given address via `i32.atomic.wait` or `i64.atomic.wait`

For the web embedding, `atomic.wake` is equivalent in behavior to executing the following:

1. Let `memory` be a `WebAssembly.Memory` object for this module.
1. Let `buffer` be `memory`([`Get`][](`memory`, `"buffer"`)).
1. Let `int32array` be [`Int32Array`][](`buffer`).
1. Let `fcount` be `count` if `count` is >= 0, otherwise `∞`.
1. Let `result` be [`Atomics.wake`][](`int32array`, `address`, `fcount`).
1. Trap if `result` is >= 2**32.
1. Return `result` converted to an `i32`.

## [JavaScript API][] changes
Expand Down