Happens-before的原则
英文:
- Each action in a thread happens-before every action in that thread that comes later in the program’s order.
- An unlock on a monitor happens-before every subsequent lock on that same monitor.
- A write to a volatile field happens-before every subsequent read of that same volatile.
- A call to start method on a thread happens-before any actions in the started thread.
- All actions in a thread happens-before any other thread successfully returns from a join method on that thread.
翻译:
- 程序顺序规则:一个线程中, 每一个操作happens-before 于该线程中的任意后续操作。
- 监视器锁规则:对监视器锁的一个解锁操作,happens-before 于随后对同一个监视器锁的加锁操作。
- volatile变量规则:对一个volatile域的写操作,happens-before 于任意后面对这个volatile域的读操作。
- 传递性规则:如果A happens-before B,且B happens-before C,那么A happens-before C。
- 线程启动规则:Thread.start()的调用会happens-before于启动线程里面的动作。
- 线程顺序规则:Thread中的所有动作都happens-before于其他线程从Thread.join中成功返回。