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

前端 未结 7 1657
误落风尘
误落风尘 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:37

    The atomic variable classes in Java are able to take advantage of Compare and swap instructions provided by the processor.

    Here's a detailed description of the differences: http://www.ibm.com/developerworks/library/j-jtp11234/

提交回复
热议问题