*True* *However, it's important to note that in some cases, multiple loads might be necessary for correctness, such as in certain lock-free algorithms or when implementing specific memory ordering requirements* *citation <https://bartoszmilewski.com/2008/12/01/c-atomics-and-memory-ordering/>.**When working with atomic variables, it's best to:* - *Only use atomic operations when necessary for thread-safety and synchronization.* - *Choose the appropriate memory ordering for each operation to avoid overly strict guarantees when not needed.* - *Consider using higher-level synchronization primitives (like mutexes or channels) for more complex scenarios, as they can be easier to reason about and may have better performance characteristics in some cases.*
*Remember, the key is to balance correctness with performance, using atomic operations judiciously and only when required for proper synchronization between threads.* On Thursday, November 7, 2024 at 3:13:38 PM UTC-8 Ian Lance Taylor wrote: > On Thu, Nov 7, 2024 at 2:54 PM Roger <rogerdilm...@gmail.com> wrote: > > > > True or false, it's better to avoid loading atomic variables > unnecessarily? > > Questions like this always depend on the context. There is no answer > that is always correct in all situations. > > That said, all else being equal, it's better to avoid loading any > variable unnecessarily. That applies to both ordinary variables and > atomic variables. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/3d9a1a9f-bb76-4abb-9ac0-8c24bf8d78c3n%40googlegroups.com.