Volatile vs. Interlocked vs. lock

后端 未结 9 1710
悲哀的现实
悲哀的现实 2020-11-22 05:54

Let\'s say that a class has a public int counter field that is accessed by multiple threads. This int is only incremented or decremented.

T

9条回答
  •  自闭症患者
    2020-11-22 06:11

    I second Jon Skeet's answer and want to add the following links for everyone who want to know more about "volatile" and Interlocked:

    Atomicity, volatility and immutability are different, part one - (Eric Lippert's Fabulous Adventures In Coding)

    Atomicity, volatility and immutability are different, part two

    Atomicity, volatility and immutability are different, part three

    Sayonara Volatile - (Wayback Machine snapshot of Joe Duffy's Weblog as it appeared in 2012)

提交回复
热议问题