What is the purpose of 'volatile' keyword in C#

前端 未结 6 2218
抹茶落季
抹茶落季 2020-12-05 15:23

What is the purpose of volatile keyword in C#?

Where would I need to use this keyword?

I saw the following statement, but I am unable to underst

6条回答
  •  爱一瞬间的悲伤
    2020-12-05 15:25

    MSDN will summarize better than I....

    "The volatile keyword indicates that a field might be modified by multiple threads that are executing at the same time. Fields that are declared volatile are not subject to compiler optimizations that assume access by a single thread. This ensures that the most up-to-date value is present in the field at all times."

    http://msdn.microsoft.com/en-us/library/x13ttww7(v=VS.100).aspx

提交回复
热议问题