[concurrency-interest] Synchronization automatic with Lock in
dholmes at dltech.com.au
Wed Oct 12 19:19:56 EDT 2005
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.
From: concurrency-interest-bounces at cs.oswego.edu
[mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Vijay
Sent: Wednesday, 12 October 2005 3:07 PM
To: concurrency-interest at altair.cs.oswego.edu
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.. A successful lock operation acts like a successful monitorEnter
b.. A successful unlock operation acts like a successful monitorExit
So does that mean that acquiring a lock is as good as entering a
synchronization block i.e. will all the buffered variables be discarded?
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?
My apologies if this doubt is too basic.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest