Which is more efficient, basic mutex lock or atomic integer?

前端 未结 7 1663
误落风尘
误落风尘 2020-12-07 12:57

For something simple like a counter if multiple threads will be increasing the number. I read that mutex locks can decrease efficiency since the threads have to wait. So, to

7条回答
  •  孤街浪徒
    2020-12-07 13:43

    atomic integer is a user mode object there for it's much more efficient than a mutex which runs in kernel mode. The scope of atomic integer is a single application while the scope of the mutex is for all running software on the machine.

提交回复
热议问题