C
C++Liliput
It seems that the keyword "volatile" is used to make sure that threads
reading (or writing to) the same data should see a consistent picture
of the variable i.e. updates made to the common data should
immediately get reflected to other threads that are using it. However
I have never faced this issue in y multi-threaded code even though the
common variables are not declared volatile. So is this just a matter
of coincidence that I have had no runtime issues or is it that the
"volatile" keyword is required in some special situations that perhaps
my code does not encounter? I would love to know a demonstrable piece
of code that really shows the relevance of volatile variables in multi-
threaded environment.
reading (or writing to) the same data should see a consistent picture
of the variable i.e. updates made to the common data should
immediately get reflected to other threads that are using it. However
I have never faced this issue in y multi-threaded code even though the
common variables are not declared volatile. So is this just a matter
of coincidence that I have had no runtime issues or is it that the
"volatile" keyword is required in some special situations that perhaps
my code does not encounter? I would love to know a demonstrable piece
of code that really shows the relevance of volatile variables in multi-
threaded environment.