Любопытно, с phtread_mutex'ами проделывать подобные операции всегда безопасно. (http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libpthread/pthread_mutex.c?rev=1.27&content-type=text/x-cvsweb-markup) /* * Note regarding memory visibility: Pthreads has rules about memory * visibility and mutexes. Very roughly: Memory a thread can see when * it unlocks a mutex can be seen by another thread that locks the * same mutex. * * A memory barrier after a lock and before an unlock will provide * this behavior. This code relies on pthread__simple_lock_try() to issue * a barrier after obtaining a lock, and on pthread__simple_unlock() to * issue a barrier before releasing a lock. */
Неужели synchronized в Java работает по-другому? Вот, например, в статье в Java World за 2001ый год Алан Голуб пишет буквально следующее: "Memory barriers surround synchronization To summarize, synchronization implies a memory barrier. In that case, two exist: one barrier associated with entering a synchronized block or method and another associated with leaving it" Неужели "гонит"?
no subject
Date: 2007-04-12 02:41 am (UTC)безопасно.
(http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libpthread/pthread_mutex.c?rev=1.27&content-type=text/x-cvsweb-markup)
/*
* Note regarding memory visibility: Pthreads has rules about memory
* visibility and mutexes. Very roughly: Memory a thread can see when
* it unlocks a mutex can be seen by another thread that locks the
* same mutex.
*
* A memory barrier after a lock and before an unlock will provide
* this behavior. This code relies on pthread__simple_lock_try() to issue
* a barrier after obtaining a lock, and on pthread__simple_unlock() to
* issue a barrier before releasing a lock.
*/
Неужели synchronized в Java работает по-другому? Вот, например, в статье в Java World за 2001ый год Алан Голуб пишет буквально следующее:
"Memory barriers surround synchronization To summarize, synchronization implies a memory barrier. In that case, two exist: one barrier associated with entering a synchronized block or method and another associated with leaving it"
Неужели "гонит"?