What is the “volatile” keyword used for?

前端 未结 8 970
一个人的身影
一个人的身影 2020-11-28 19:35

I read some articles about the volatile keyword but I could not figure out its correct usage. Could you please tell me what it should be used for in C# and in

8条回答
  •  忘掉有多难
    2020-11-28 20:29

    For both C# and Java, "volatile" tells the compiler that the value of a variable must never be cached as its value may change outside of the scope of the program itself. The compiler will then avoid any optimisations that may result in problems if the variable changes "outside of its control".

提交回复
热议问题