After I finish reading the article, "Atomicity, volatility and immutability are different, part three", written by Eric Lippert, I come up with a question that even if I put a lock around a reference type variable, but what if the cpu once gets its hand on the variable stored in the main memory and loads the variable into its register page and read the variable only from its register since, assuming the volatile keyword is not applied to this variable. So the change made to this variable on other threads cannot be seen by this thread.
I am not sure if my logic is correct here. From the article, it indicates there is no need to declare a field as volatile if there is a lock around it. Could anyone please explain to me what exactly happen if the code use a lock to control the access to the variable.