Is there any advantage of using volatile keyword in contrast to use the Interlocked class?

后端 未结 5 1893
时光取名叫无心
时光取名叫无心 2021-02-04 15:59

In other words, can I do something with a volatile variable that could not also be solved with a normal variable and the Interlocked class?

5条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 16:16

    This is a fairly complex topic. I find Joseph Albahari's writeup to be one of the more definitive and accurate sources for multithreading concepts in the .NET Framework that might help answer your question.

    But, to quickly summarizes there is a lot of overlap between the volatile keyword and the Interlocked class as far as how they can be used. And of course both go way above and beyond what you can do with a normal variable.

提交回复
热议问题