Example of a memory consistency error when using volatile keyword?
问题 From docs: Using volatile variables reduces the risk of memory consistency errors But this means that sometimes volatile variables don't work correct? Strange how it can be used - for my opinion it is very bad code that sometimes work sometimes not. I tried to Google but didn't find example memory consistency error with volatile. Could you please propose one? 回答1: The issue is not so much that volatile works unreliably. It always works the way it is supposed to work. The problem is that the