Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are atomic objects protected against race conditions?

As far as I know they aren't.

Atomic objects are free of data races, yet they can still suffer from race conditions: two threads might start in an unpredictable order making the program outcome non-deterministic.

Shared data would be "safe" (protected by atomics) but the sequence or timing could still be wrong.

Can you confirm this?

like image 476
Ignorant Avatar asked Jan 26 '26 05:01

Ignorant


1 Answers

Yes, you are correct that non-atomic operations may still have race condition. If you have non-atomic operations that depend on the state of the atomic object without interference from other threads, you need to use another synchronization technique to maintain consistency.

Atomic operations on the atomic object will be consistent, but not race-free. Non-atomic operations using the atomic object are not race-free.

like image 95
mattm Avatar answered Jan 28 '26 20:01

mattm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!