RE: Synchronization automatic with Lock in JVM5.0?
Yes acquiring a Lock is equivalent in memory model terms to entering a
synchronized block; and similarly for releasing a Lock and leaving a
The new memory model doesn't talk about buffering and caches and main
memory, because there is much more to it than just that. Rather it defines a
happens-before relationship between actions in a thread. If you can establish
that a write to a variable happens-before a read of that variable, then the read
will see the value written. Similarly happens-before can establish a relative
ordering between two actions.
So when you say "all buffered variables will be discarded" you need to be
careful about what you mean. What the JMM says is that unlock() of a lock X
happens-before a subsequent lock() of X. This means that only actions performed
by the thread that does the unlock() will be visible to the thread that does the
lock(). Actions in other threads where X has not been lock()ed or unlock()ed
need not be visible.
-----Original Message----- From:[hidden email]
[mailto:[hidden email]]On Behalf Of
Vijay Sent: Wednesday, 12 October 2005 3:07 PM To:[hidden email] Subject:
[concurrency-interest] Synchronization automatic with Lock in
I am using Sun JVM 5.0.
The javadoc for Lock interface says
"All Lock implementations
must enforce the same memory synchronization semantics as provided by
the built-in monitor lock:
A successful lock operation acts like a successful monitorEnter
A successful unlock operation acts like a successful
monitorExit action "
So does that mean that acquiring a lock is as good as
entering a synchronization block i.e. will all the buffered variables
Also does that mean that releasing a lock is as good as
leaving a synchronization block i.e. will all the buffered changed variables
be flushed to RAM?