Does memory visibility depend on that monitor? Lock For example the following code: Threads start at the same time and threads Update to If this is true then please give me the > There is no reason to not be visible. > Further, however, they say that the monitor should be the same, but it is not contained with the aforesaid statements. It seems that the process of local memory flush is not as simple as described in the earlier statement and every can not be on lock release? Yes, it depends on whether you can read about this in the relevant section "17.4. 4. Synchronization order ": With an after-lock operation on an unlocked action-M on Monitor M Synchronization (where" later "is defined according to the synchronization order). You can see, a solid monitor object is specified there If an action x synchronizes Does the following verb y, then we also have Hb (x, y). Therefore, your updates will probably be executed sequentially with missing updates. A after lock
B has been acquired, is this enough for memory visibility?
integer state; // Share // Synchronize a synchronized (A) {state + = 1; } Thread. Sleep (10000000); // Thread B. Thread Solid (1000); Synchronize (B) {state + = 1; }
b can be arbitrarily high during sleep, to ensure that this thread
a used
state variable. Threads
A before thread
B does not use the
state shared variable.
When a thread is associated with a synchronized block as part of the monitored release , JMM requires that the local processor cache be flown, in the same way in the main memory, as part of obtaining a monitor while entering a synchronized block, the local cache is invalidated so that If you read in Will the Ori and the local cache.
state variable yarn
b
This process guarantees that when a variable is written by a variable during a synchronized block read by a given monitor and another thread, the same monitor During a synchronized block protected by, typing on the variable will be seen by reading threads.
m . If the monitors are different, then you are not synchronizing - with regards, therefore, before you do not - before the connection (from 17.4.5):
No comments:
Post a Comment