Because atomics are slower. They slow down the calling thread, and they may slow down other threads as well, potentially even ones not accessing the same atomics. They may also inhibit the compiler from performing certain reordering optimizations that it would otherwise perform.
When to NOT use Atomic Operations? [closed]
-
10-10-2022 - |
Question
I can think of reasons when it doesn't matter, and 1 situation where you may NOT want to use them which is when you want to test a design for behaviour with non-atomic operations.
What are some other reasons? Specifically I am working on a project that is having some rare race conditions, because a test is not using atomic increments. I am wondering, why would I not just always use atomic increments when a function for it already exists?
Thanks!
Solution
OTHER TIPS
Atomic operations are potentially, and likely, more expensive than their non-atomic equivalent. In cases where synchronization between threads isn't needed, for instance updating an unshared local, atomiticy adds unnecessary overhead and should be avoided.