Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Is there a way to Send without enforcing happens-before semantics?
I am writing a datastructure that relies on acquire/release atomics to do something complicated.
I would like to know if my datastructure should be marked as !Send
.
My problem boils down to: is there a way to Send a value from a thread to another without enforcing an happens before relationship.
In other words,
// thread 1
atomic1.store(1, Ordering::Relaxed); // A
atomic1.store(2, Ordering::Relaxed); // B
atomic2.store(Ordering::Release); // S
// thread 2
let version = atomic2.load(Ordering::Acquired); // L
somehow_send_to_thread3(version); // SD
// thread3
let version = somehow_receive_sent_version(); // RCV
let val = atomic1.load(Ordering::Acquire);
// Assuming we got the version sent in SD.
// Are we certain to have assert_eq!(val, 2); ?
My understanding is that we have
A happens-before B
B happens-before S
S happens-before L
L happens-before SD
However I don't see any argument to justify an happens before relationship in thread 3.
Could someone implement a strange channel based on relaxed atomics and end up
with the value 1 in val?
Is "causality" associated to the sheer fact of having that value of "version" in our hands is sufficient to ensure the happens-before relationship?
Extra related question: is atomics ordering in theory and in practise just about instruction reordering, or is the memory model broader than this, and could in theory be used for cache coherence strategies for instance?
2 posts - 2 participants
🏷️ rust_feed