Is there a concept of "Happens-Before" in Rust?
Hi Rusteaceans,
I am coming from Java, and java provides a memory model, and i know for a fact , Rust doesn't.
I wanted to know how does Rust handle visibility issues?
In Java, a volatile variable access, synchronized provides a happens-before relationship
For example:
from Thread 1:
i = 10; j = 20;
done = true; // done is volatile
from Thread 2:
if(done == true)
assert i == 10 && j == 20;
here there is a happens before relationship when two threads access the same volatile variable.
I don't have to declare i and j as volatile, i believe, the JVM uses store/release and load/acquire memory barriers on \done\ variable to create this happens-before relationship.
How does Rust handle this?
Should i send all the variable of interest over a channel, which provides that happens before relationship?
struct State {
i: i32,
j:32
}
What about in shared memory concurrency?
any widely used technique you can refer me to ?
Thanks!