Java memory model : compiler rearranging code lines
It is well known that Java Language allows compliers to re-arrange lines of compiled code as long as the re-order makes no difference to the code semantics. However , the compiler is required to only bother about sematics as seen from the current thread . If this re-order affects semantics in a multithreaded situation , it usually causes concurrency issues ( memory visibility ) My question(s) : What is achieved by allowing this freedm to the compiler ? Is it really possible for the compiler to produce code which is more efficient by rearranging the code ? I am yet to see a practical case for