-
Notifications
You must be signed in to change notification settings - Fork 10
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, shared struct fields, and references #6
Comments
Interesting, if refs existed, My initial thought was exactly "both overloads seem fine". Given that, I strongly prefer no dependence on refs, but instead this proposal giving another (edit: maybe not another since you were already considering, but reinforcing) motivating use case for the refs proposal. |
If we ever plan to support private fields in shared structs (which won't be useful unless we have shared functions), we'll probably need shared struct class Data {
#value = 1;
foo() {
return Atomics.compareExchange(ref this.#value, 1, 2)
}
} I wrote up a more detailed (and possibly buggy) example of this (along with a sketch of "shared modules" and "shared functions") here: https://gist.github.com/rbuckton/4bcf5ba532f594b5f9a076cb86c4a4e8 |
(which still doesn't gate this proposal on |
I suppose its still feasible to avoid shared struct class ValueHolder {
value;
constructor(value) { this.value = value; }
}
shared struct class Data {
#value = new ValueHolder(1);
foo() {
return Atomics.compareExchange(this.#value, "value", 1, 2);
}
} At the cost of the extra memory needed. |
In the slides there's an example of a possible future API for using shared structs with
Atomics
. I had been considering the same thing with https://github.com/rbuckton/proposal-struct and https://github.com/rbuckton/proposal-refs. The examples in the slides are as follows:The approach I had been considering would have used
ref
instead:That said, its not necessary that we take a dependency on https://github.com/rbuckton/proposal-refs. Should that proposal be accepted once I've had the opportunity to present it, I had intended to introduce
ref
-style "overloads" forAtomics
for typed arrays as well, i.e.:Atomics.store(ref int32Array[0], 42)
, so in essence both patterns could exist.The text was updated successfully, but these errors were encountered: