Visible, object tectonic function had be notted call, but the adduction that can have obtained Object object example through Objects[i].reference.
If put code to multi-line Cheng environment next moving, when some line Cheng is implementing this code JVM or the operating system undertook line Cheng switch, other line Cheng can discover Msg object has not been been apparently empty, bring about the judgement statement If(objects[i].reference of Lazy Load==Null) does not hold water. Line Cheng thinks the object has built a success, the member variable that may use a target subsequently perhaps calls the method of this object example, cause uncertain error finally.
Of the reason is to be on the SMP machine that shares memory, every CPU has his Cache and register, share same a systematic memory. So CPU may the executive order that trends adjusts a statement, with better have collateral operation and operation result and advocate memory is synchronous. Order adjusts such code to bring about DCL invalidation possibly also. After-thought faces the introduction of Java memory model ago, can regard Main Memory here physical memory of the system, consider as Thread Working Memory the Cache of CPU interior and register, without the protection of Synchronized, the content of Cache and register won't be mixed in time advocate the content of memory is synchronous, bring about Cheng of a line to cannot see another line Cheng is a few righter thereby alter variably.
Combinative code 3 come illustrate, hypothesis Resource kind implementation is as follows:
Class Resource{Object Obj;}
Namely Resource kind variable of an Obj member cited an example of Object. Assume 2 lines Cheng is moving, its condition uses following simplifying the graph expresses:

Graph 2
Thread-1 constructed now Resource example, altered in initialization process a few content of Obj. Exit synchronous code paragraph hind, because adopted synchronous mechanism, thread-1 place does alter metropolis report arrives advocate in putting. Next Thread-2 obtained Res of new Resource example variable, because did not use Synchronized protection,so Thread-2 won't have the operation of renovation job memory. If before a copy that there had been Obj example in the working memory of Thread-2, load operation won't be executed so when Thread-2 is carrying out Use to operate to Obj, cannot see the Thread-1 change to Obj so, this can bring about wrong operation result apparently. In addition, thread-1 is in exit synchronous code paragraph always carry out to Ref and Obj write advocate also inaccuracy decides the operation order that put, although Thread-2 carried out Load to Obj,operate so, possible also read-only the data of the first try condition to Obj. (Note: The Load/use here all points to the operation that JMM defines)
Have unwilling to give up of a lot of people, tried to think up the way with a lot of clever essence to solve this problem, but failed finally. In fact, no matter be of current JMM or the JMM model that had referred as JSR,increase, DCL cannot be used normally. The paper in William Pugh " Fixing The Java Memory Model " in the detailed a few hard injuries that discussed JMM, more the attempt gives out a new memory model, have fun at the reference material that the reader of thorough research can refer to article hind.
Previous 1 2 3 45 6 7 8 Next