-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Atomics.wait and SuspendAgent disagree about the domain of valid timeouts #2914
Comments
Nice find, this is definitely a bug. The right fix here is to have SuspendAgent take a mathematical value for the number of milliseconds, but as you point out about the fractional component, there's a normative question: what normative requirement ought 262 require on the resolution of timers? I think reasonable lower bounds to normatively require are either
(1) obviously gives the most flexibility, and also allows hosts to degrade timing resolution for whatever reason. But that's a weak reason practically speaking, as Atomics.wait requires SABs and the ability to block, which means off-main-thread, where you can make your own high-res timers. Still, I see no reason to disallow flexibility here. I'm not sure what we get from requiring any resolution, so this is my preference. (2) may be desirable as a baseline for all JS implementations, and is a reasonable interpretation for what test262 already requires. |
@syg I'm a little confused about what the proposed options mean here, could you please elaborate on them? Does the first option mean that the lower bound is implementation defined and arbitrary, but the specification requires that a lower bound exists? Does the second option mean to round or truncate to whole milliseconds? |
The first option means compliant implementations can coarsen Atomics.wait to whatever it wants. Whenever someone calls Atomics.wait(x) for any finite x, the implementation can choose to wait any (possibly different) actual finite time y and still be considered compliant. The normative requirement is that the delta y - x is finite and ≥ 0. The second option means that compliant implementations cannot coarsen Atomics.wait timer resolution beyond milliseconds. Whenever someone calls Atomics.wait(x) for any finite x, the implementation must wait for an actual finite time y such that 0 ≤ y - x ≤ 1 ms to be considered compliant. I.e. it has to wait at least x, but can round up to whole milliseconds. I think (2) is both too restrictive on implementations and also undesirable -- given things like Spectre I'd like implementations to reserve the right to coarsen resolution as they see fit. |
Option 1 got consensus at the November 2022 TC39. |
… lower bound Fixes tc39#2914
… lower bound Fixes tc39#2914
How does the suspension duration depend on the passed minimumTimeout? After the change the spec says:
So it's any duration between 0 s and timeout milliseconds, IIUC. Where timeout is the sum of minimumTimeout and an unknown (not even necessarily the same on each invocation) non-negative number. Wouldn't it be equivalent and simpler to say like: pick any duration (which may depend on anything, including some function of minimumTimeout, or not at all) and suspend for it? |
Description:
Atomics.wait
sets t to either +∞ or a nonnegative mathematical value that may have a fractional component, and if SuspendAgent is invoked it receives that value as its timeout. But timeout is specified to be a non-negative integer, which excludes +∞ and non-integer mathematical values, making the invocation inconsistent.eshost Output:
Of the implementations that support
Atomics.wait
, most appear to respect a fractional component but GraalJS appears to truncate it.The text was updated successfully, but these errors were encountered: