zoukankan      html  css  js  c++  java
  • 《Java并发编程实战》笔记-Happens-Before规则

    Happens-Before规则

    程序顺序规则。如果程序中操作A在操作B之前,那么在线程中A操作将在B操作之前执行。

    监视器锁规则。在监视器锁上的解锁操作必须在同一个监视器锁上的加锁操作之前执行。

    volatile变量规则。对volatile变量的写入操作必须在对该变量的读操作之前执行。

    线程启动规则。在线程上对Thread.start的调用必须在该线程中执行任何操作之前执行。

    线程结束规则。线程中的任何操作都必须在其他线程检测到该线程已经结束之前执行,或者从Thread.join中成功返回,或者在调用Thread.isAlive时返回false。

    中断规则。当一个线程在另一个线程上调用interrupt时,必须在被中断线程检测到interrupt调用之前执行(通过抛出InterruptedException,或者调用isInterrupted和Interrupted)。

    终结器规则。对象的构造函数必须在启动该对象的终结器之前执行完成。

    传递性。如果操作A在操作B之前执行,并且操作B在操作C之前执行,那么操作A必须在操作C之前执行。

    以下是英文描述happens-before,The happens-before relation defines when data races take place.

    • An unlock on a monitor happens-before every subsequent lock on that monitor.
     
    • A write to a volatile field happens-before every subsequent read of that field.
     
    • A call to start() on a thread happens-before any actions in the started thread.
     
    • All actions in a thread happen-before any other thread successfully returns from a join() on that thread.
     
    • The default initialization of any object happens-before any other actions (other than default-writes) of a program.
  • 相关阅读:
    Codeforces 1045C Hyperspace Highways (看题解) 圆方树
    Codeforces 316E3 线段树 + 斐波那切数列 (看题解)
    Codeforces 803G Periodic RMQ Problem 线段树
    Codeforces 420D Cup Trick 平衡树
    Codeforces 295E Yaroslav and Points 线段树
    Codeforces 196E Opening Portals MST (看题解)
    Codeforces 653F Paper task SA
    Codeforces 542A Place Your Ad Here
    python基础 异常与返回
    mongodb 删除
  • 原文地址:https://www.cnblogs.com/birdstudio/p/6644258.html
Copyright © 2011-2022 走看看