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

add documentation for atomics #1516

Open
andrewrk opened this issue Sep 13, 2018 · 3 comments
Open

add documentation for atomics #1516

andrewrk opened this issue Sep 13, 2018 · 3 comments
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Sep 13, 2018

moved from #367

  • @fence
  • @cmpxchgStrong and @cmpxchgWeak
  • @atomicRmw
  • builtin atomic memory ordering enum
  • explain when to use atomics and when to use volatile
  • talk about data races and multithreaded programming
  • talk about lock free programming
@andrewrk andrewrk added the docs label Sep 13, 2018
@andrewrk andrewrk added this to the 0.4.0 milestone Sep 13, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Apr 8, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 20, 2019
@andrewrk andrewrk added the contributor friendly This issue is limited in scope and/or knowledge of Zig internals. label 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.8.0 Oct 10, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@nacho00112
Copy link

I need this, I wasn't able to understand it reading the documentations of other languages,
they have a lot of different stuff like memory order consume, relaxed and seq_cst

@nacho00112
Copy link

If someone need this, I recommend this article: https://dev.to/kprotty/understanding-atomics-and-memory-ordering-2mom

@Pyrolistical
Copy link
Contributor

Pyrolistical commented May 14, 2024

Both @cmpxchgStrong and @cmpxchgWeak seem to have incorrect documentation.

returning null if the current value is not the given expected value.

That does not match the code snippet:

fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_value: T) ?T {
    const old_value = ptr.*;
    if (old_value == expected_value) {
        ptr.* = new_value;
        return null;
    } else {
        return old_value;
    }
}

Assuming the code snippet is correct, then should it read:

returning the current value if it is not the given expected value.

toziegler added a commit to toziegler/zig that referenced this issue Jun 24, 2024
The previous wording was incorrect as it indicated that `@cmpxchgStrong` and `@cmpxchgWeak` return `null` on "failure" even though it returns `null` on success and the current value of the atomic on "failure", see ziglang#19979. 

Further documentation might be helpful as described in ziglang#1516.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs
Projects
None yet
Development

No branches or pull requests

3 participants