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!

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top