Java Concurrent happens-before

时间:2014-04-29 16:38:32   收藏:0   阅读:511

   happens-before relation on memory operations such as reads and writes of shared variables. The results of a write by one thread

are guaranteed to be visible to a read by another thread only if the write operation happens-before the read operation.

  The synchronized and volatile constructs, as well as the Thread.start() and Thread.join()methods, can form happens-before 

relationships. In particular:

entry) of that same monitor. And because the happens-before relation is transitive, all actions of a thread prior to unlocking

happen-before all actions subsequent to any thread locking that monitor.

memory consistency effects as entering and exiting monitors, but do not entail mutual exclusion locking.

 

  The methods of all classes in java.util.concurrent and its subpackages extend these guarantees to higher-level synchronization.

In particular:

removal of that element from the collection in another thread.

submitted to an ExecutorService.

result via Future.get() in another thread.

actions subsequent to a successful "acquiring" method such as Lock.lockSemaphore.acquireCondition.await, and CountDownLatch.await on

the same synchronizer object in another thread.

happen-before those subsequent to the corresponding exchange() in another thread.

action happen-before actions subsequent to a successful return from the corresponding await in other threads.

Java Concurrent happens-before,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!