What is the memory order of `Atomic::new`

Why atomic::store has a memory order argument,
while atomic::new does not.
I think atomic::new also makes some store to memory.

I know that atomic.store(Release) and atomic.load(Acquire) makes a happen-before relationship.

Does atomic.new() and atomic.load(Acquire) make a happen-before relationship?

It doesn't make sense to have an ordering for it, because it's not defineable, and it's plain unnecessary. Until an atomic value doesn't exist, no other concurrent actor can possibly access it in any way (read or write). And since there's literally no "before", one can't define a "happens-before" relationship.

6 Likes

I think new doesn't have a memory order argument because it happens only on one thread.

Suppose one thread does AtomicUsize::new(0) and another thread then does atomic.load(Acquire) on that atomic. There must already be a happens-before relation between these two events in order for the second thread to have gotten a reference to the atomic.

4 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.