What does it mean by “synchronized”? 1) Mutual Exclusive Only one thread can enter synchronized block. 2) Guarantee no reordering Instruction inside synchronized block can reordered between themselves. E.g. 4, 6, 5 Instruction outside synchronized block can reorder between themselves. E.g. 2, 3 ,1. Instruction in synchronized block cannot be reordered to mix with outside block (1, 5, 2, 3) Instruction outside synchronized block cannot be reordered to mix with in block (7, 5, 8, 9) 3) Guarantee to get value from memory all the time, not from cache 4) Volatile variable observe next page (need validation) After all instruction in a synchronized block get executed. All change values are pushed into memory from local cache of the thread. Also as we know data move does not work on single variable, therefore the cache line which contains the changed value got pushed to memory too. Cost of the lock in "synchronized" 1) Memory Synchronization 2) Mutual Exclusi...
Comments
Post a Comment