Search code examples
c#volatilesingle-threaded

Is volatile useful at all in a singlethreaded application in C#?


Is there any case in which volatile is useful in the context of single-threaded programming? I know it's used to make sure the value of the variable is always actually checked in memory so is there any case in which that value may change (in a ST app) in a way that the app/compiler won't notice?


Solution

  • No, it's not necessary. It is used to synchronize the memory content between the threads which in case you have only one it doesn't make sense.