Posts

Showing posts with the label race condition

Understanding volatile keyword in java in details

What is Atomic ? The term atomic is related to the atom, once considered the smallest possible unit. When computer code is considered atomic it can not be interrupted during its execution, We can also define atomic code as code that can’t be found in an intermediate state. Atomicity in Java - Java specifies that basic loading and storing of variable is the atomic. That means the value of the variable can’t be found in a interim state during the store not be changed in the middle of loading the variable to a register. Java Memory Model – Unfortunately , java’s memory model is a bit more complex. Threads are allowed to hold the values of variable in local memory. In that case, when one thread changes the values of the variable, another thread may not see the changed value. This is particularly in loops where looping is controlled by a variable. The lopping may be have already loaded the value of the variable into the register and does not necessary notice when another thread cha...