questionmark
questionmark

Reputation: 29

does atomic operation synchronize?

Does atomic operation synchronize between threads? I know that no one thread can see such operation undone, but does it synchronize? For example if I write to some var in one thread, and read after(in time domain) from another, is there possibility that I still can see old value?

Upvotes: 0

Views: 933

Answers (1)

pveentjer
pveentjer

Reputation: 11307

Atomics by default provide sequential consistency (SC). SC doesn't need to respect the real time order. So it could be that after a write has executed (and even retired), when a different CPU does a load, it will not see that write. So in the real time order the load has occurred after the write, but in the memory order it has 'happened before' the write.

See the following answer for more info: Does 'volatile' guarantee that any thread reads the most recently written value?

Upvotes: 1

Related Questions