简体   繁体   English

“发生之前”Java与挥发性领域的澄清有关

[英]“Happens-before” Java relate to volatile fields clarifiacation

I am looking in to Java Concurrency and found following resources to refer, 我正在寻找Java Concurrency并找到以下资源来引用,

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

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

I am bit confused about a statement regarding Happens-before relation , 关于Happens-before关系的陈述,我有点困惑,

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. 我不清楚上述声明中的Bold声明。

Could someone give me an idea what does it exactly means in relation to that statement ? 有人能告诉我它与该陈述的确切含义是什么?

Entering/exiting monitors trigger a happens-before barrier like accessing a volatile variable but they also trigger mutual exclusion locking. 进入/退出监视器会触发发生之前的障碍,例如访问volatile变量,但它们也会触发互斥锁定。 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. volatile变量具有before-before功能但没有任何锁定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM