Synchronization automatic with Lock in JVM 5.0?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Synchronization automatic with Lock in JVM 5.0?

Vijay-10
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 action
  • 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.

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

RE: Synchronization automatic with Lock in JVM5.0?

David Holmes
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: [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 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 successful lock operation acts like a successful monitorEnter action
  • 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.

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest