Question

I am looking in to Java Concurrency and found following resources to refer,

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/package-summary.html

http://docs.oracle.com/javase/tutorial/essential/concurrency/memconsist.html

I am bit confused about a statement regarding Happens-before relation ,

A write to a volatile field happens-before every subsequent read of that same field. Writes and reads of volatile fields have similar memory consistency effects as entering and exiting monitors, but do not entail mutual exclusion locking.

I am not clear about the statement in Bold in above statement.

Could someone give me an idea what does it exactly means in relation to that statement ?

Was it helpful?

Solution

Entering/exiting monitors trigger a happens-before barrier like accessing a volatile variable but they also trigger mutual exclusion locking. A mutual exclusion (or mutex) ensures that if more than one thread attempts to cross the barrier one thread may be locked out until the other releases the mutex.

volatile variables have the happens-before feature but without any locking.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top