I am aware of instruction reordering but in the following link Will this AssertionError never be thrown in this case? In approved answer there is a line:
first the the publishing the reference is re-ordered with variable n (there is no happens-before, so this is allowed). Thread1 creates an instance of Holder"
I could not understand the line. Could anyone explain this. How this reordering would happen. I am aware thread.start()
has happen before relationship.
what i understand about reordering in java is that instructions can be reordered if they do not have happen before relationship.
int c=0;
int d=1;
can be reordered as
int d=1;
int c=0;
But user explained if thread.starts()
would not have happen before relationship then publishing the reference might get reordered with variable n(It is allowed). I couldn't understand how. Reference is in other class and variable n is in different class.