Java内存Happen-Before

  • 在Thread.start以前的操做,hb 线程里面的操做
  • 对一个锁的解锁,hb 从新得到锁
  • 一个线程里的全部操做,hb其余线程调用这个线程的join返回后。
  • 对一个volatile的写入操做,hb读取操做
  • 对一个并发集合(CopyOnWriteList等)的写入操做,hb于对他的删除、读取操做

 

  hb的含义,是以前的操做写入的东西,对以后的操做都是可见的java

  具备传递性,若是A hb B,B hb C,那么A hb C并发

 

  • Each action in a thread happens-before every action in that thread that comes later in the program's order.
  • 在同一个线程里面,前面的操做老是 hb 后面的操做
  • An unlock (synchronized block or method exit) of a monitor happens-before every subsequent lock (synchronized block or method 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.
  • 对于同一个锁,释放锁以前的操做,老是 hb 以后获取锁的操做。所以,以前获取锁的线程,老是hb以后获取锁的线程。
  • 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.
  • 对Volatile的写操做,老是hb读操做。对volatile的读写在进入和退出锁上有类似的的内存一致性,但不是互斥锁。
  • A call to start on a thread happens-before any action in the started thread.
  • 在Thread.start以前发生的,老是hb 线程里面执行的
  • All actions in a thread happen-before any other thread successfully returns from a join on that thread.
  • 在线程里面发生的,老是hb 线程Join返回以后发生的

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

  • Actions in a thread prior to placing an object into any concurrent collection happen-before actions subsequent to the access or removal of that element from the collection in another thread.
  • 在同步集合中以前放入对象老是hb以后的读取和删除
  • Actions in a thread prior to the submission of a Runnable to an Executor happen-before its execution begins. Similarly for Callables submitted to an ExecutorService.
  • 在Executor执行以前发生的,老是hb提交的Runnable的代码
  • Actions taken by the asynchronous computation represented by a Future happen-before actions subsequent to the retrieval of the result via Future.get() in another thread.
  • 在Future里面执行的,老是hb Future.get以后发生的
  • Actions prior to "releasing" synchronizer methods such as Lock.unlockSemaphore.release, and CountDownLatch.countDown happen-before actions subsequent to a successful "acquiring" method such as Lock.lockSemaphore.acquireCondition.await, and CountDownLatch.await on the same synchronizer object in another thread.
  • 在锁释放前发生的(如Lock.unlockSemaphore.release, and CountDownLatch.countDown)老是hb 以后成功获取锁后发生的。
  • For each pair of threads that successfully exchange objects via an Exchanger, actions prior to the exchange() in each thread happen-before those subsequent to the corresponding exchange() in another thread.
  • 在两个经过Exchanger进行交换的线程,在调用exchange以前发生的,老是hb另一个线程响应exchange
  • Actions prior to calling CyclicBarrier.await and Phaser.awaitAdvance (as well as its variants) happen-before actions performed by the barrier action, and actions performed by the barrier action happen-before actions subsequent to a successful return from the corresponding await in other threads.
  • 在调用CyclicBarrier.await and Phaser.awaitAdvance以前发生的,老是hb 被内存栅栏执行的动做,内存栅栏执行的动做,老是hb 其余线程调用await返回以后
相关文章
相关标签/搜索