Here is the Rust code:
static X: AtomicI32 = AtomicI32::new(0);
fn a()
{
X.fetch_add(5, Relaxed);
X.fetch_add(10, Relaxed);
}
This code snippet is taken from the Mara Bos's excellent book.
The X
is only modified by a thread.
The book says X
only has a 0->5->15
modification order. But I think there might be another modification order possible: 0 -> 10 -> 15
. The compiler might reorder the instructions--add the 10 first-- in the function a
as Relaxed ordering does not ensure the happens-before relationship. This might happen in extremely loosely ordered hardware architecture.
What do you think?
Thanks,