WebReflection / coincident

An Atomics based Proxy to simplify, and synchronize, Worker related tasks.
MIT License
203 stars 3 forks source link

A better fix for the Atomics.wait with costrol value #28

Closed WebReflection closed 1 year ago

WebReflection commented 1 year ago

This MR uses what seems to be the best way to deal with Atomics.wait(view, index, control, ...rest) which is by doubling the buffer for the "first contact" and reading the result out of the view[1] index instead, reserving view[0] for just the control value.

This MRs also avoid locking forever workers when stuff breaks on main so that they can be freed and an error will be still thrown when/if needed, without actually letting workers hang forever.

To know more about this solution please read the ugly exchange at Mozilla https://bugzilla.mozilla.org/show_bug.cgi?id=1858092#c7 but after testing current branch in all major browsers I am confident this is the right thing to do, even if the previous hack on -1 was already solving the issue.