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

Documentation: Relaxed Memory Ordering maybe wrong statement? #368

Open
sainteckes opened this issue Nov 5, 2024 · 1 comment
Open

Documentation: Relaxed Memory Ordering maybe wrong statement? #368

sainteckes opened this issue Nov 5, 2024 · 1 comment

Comments

@sainteckes
Copy link

In the section about Relaxed Memory Ordering in the docs it is stated, that B can run before A.

loom/src/lib.rs

Line 294 in 31dfebd

//! ## Relaxed Memory Ordering

thread::spawn(move || {
  let r1 = y.load(Ordering::Relaxed); // A
  x.store(r1, Ordering::Relaxed);     // B
});
thread::spawn(move || {
  let r2 = x.load(Ordering::Relaxed); // C
  y.store(42, Ordering::Relaxed);     // D
});

How should the compiler be able to move B in front of A, if r1 is not existing at this time?
I guess you meant that D can run before C, what makes perfect sense, because D has no connection to C that is visible for the compiler.

I am quite new to understanding this stuff, so happy if you correct me :)

@sainteckes
Copy link
Author

Okay, theoretically r1 could exist because of shadowing, but this is not the point that should be done here no? :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant