Skip to content

@atomicRmw on u0 #1549

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

Closed
Hejsil opened this issue Sep 18, 2018 · 2 comments · Fixed by #4707
Closed

@atomicRmw on u0 #1549

Hejsil opened this issue Sep 18, 2018 · 2 comments · Fixed by #4707
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@Hejsil
Copy link
Contributor

Hejsil commented Sep 18, 2018

Under @atomicRmw we have "TODO right now bool is not accepted. Also I think we could make non powers of 2 work fine, maybe we can remove this restriction". If @atomicRmw where to work on u0, then one could write code that is optionally threadsafe without a lot of special casing.

const Lock = if (is_thread_safe) u1 else u0;
const Locked = if (is_thread_safe) 1 else 0;
const Unlocked = 0;

var lock: Lock = Unlocked;
...
// Do @atomicRmw on lock. @atomicRmw will be no-ops on `u0`

Idk if this is a good idea. Maybe @atomicRmw should never be no-op because that might be confusing with its description "This builtin function atomically modifies memory and then returns the previous value.". u0 has no memory to modify.

Related: #1530

@kristate
Copy link
Contributor

kristate commented Sep 18, 2018

You made a very valid point and I think that this is a bad idea to allow. @atomicRmw should never be a noop. I think that this is the nail in the coffin for u0. Integers should be backed by memory -- and they are by definition.

@BarabasGitHub
Copy link
Contributor

BarabasGitHub commented Sep 18, 2018 via email

@andrewrk andrewrk added this to the 0.4.0 milestone Sep 18, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Sep 28, 2018
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 May 3, 2019
@andrewrk andrewrk added accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. labels Dec 9, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Dec 9, 2019
@andrewrk andrewrk modified the milestones: 0.7.0, 0.6.0 Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants