Ahoj,
presne receno plati , ze ostatni vlakna po vstupu do synchronized sekce
vidi stav, ktery tam zanechalo nejake jine vlakno pred jejim opustenim
(viz druhy bod nize_
(pokud je to synchronized sekce nad stejnym objektem).
Tedy samotne opusteni nestaci, je nutne aby do te same synchronizovane
sekce to druhe vlakno vstoupilo.
Ve specifikaci je presne popsnane co je "happens before" (necituji ted
primo z JSR 133):
* Each action in a thread /happens-before/ every action in that
thread that comes later in the program order
* An unlock on a monitor /happens-before/ every subsequent lock on
that same monitor
* A write to a volatile field /happens-before/ every subsequent read
of that same volatile
* A call to |Thread.start()| on a thread /happens-before/ any
actions in the started thread
* All actions in a thread /happen-before/ any other thread
successfully returns from a |Thread.join()| on that thread
Na vyse uvedene je nutne pouzit tranzitivitu, protoze relace happens
before je tranzitivni.
Volatile je jen jedno mozne reseni jak opravit Double Check ;-)
Lukas
jan_bar napsal(a):
Ahoj,
sice pozdě, ale rád bych podotknul, že "pri opousteni synchronized sekce se
invaluduje cache a tim se zajisti "prenos" dat mezi procesory" neplatí.
Pokud by platilo, nebyl by Double Check Problem. Pouze volatile zajistí
"happens before".
Honza