[concurrency-interest] Synchronization automatic with Lock in JVM5.0?

David Holmes dholmes at dltech.com.au
Wed Oct 12 19:19:56 EDT 2005


Vijay,

Yes acquiring a Lock is equivalent in memory model terms to entering a
synchronized block; and similarly for releasing a Lock and leaving a
synchronized block.

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.

David Holmes
  -----Original Message-----
  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
JVM5.0?


  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
action
    b.. 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 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.
  Thanks.......Vijay.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20051013/b30941e5/attachment-0001.htm


More information about the Concurrency-interest mailing list