Java Concurrency Programming Practice Note-happens-before rules

Source: Internet
Author: User

Happens-before rules

Program Order rules. if action A in the program is before action B, then a operation in the thread will be executed before the B operation.

Monitor lock rules. the unlock operation on the monitor lock must be performed before the lock operation on the same monitor lock.

volatile variable rules. a write operation on a volatile variable must be performed before the read operation on the variable.

thread start rule. the call to Thread.Start on the thread must be executed before any operation is performed on the threads.

thread end rule. any action in the thread must be executed before another thread detects that the thread has ended, or it returns successfully from Thread.Join, or False when the thread.isalive is called.

The interrupt rule. when a thread calls interrupt on another thread, it must be executed before the interrupt call is detected by the interrupted thread (by throwing interruptedexception, or call isinterrupted and interrupted).

The finalizer rule. the constructor of the object must be completed before the finalizer of the object is started.

transitivity. If operation A is performed before action B and action B is performed before Operation C, then operation a must be performed before Operation C.

The following is an English description of happens-before,the Happens-before relation defines when data races take place.

    • An unlock in a monitor happens-before every subsequent lock on the that monitor.
    • A write to a volatile field happens-before every subsequent read of the that field.
    • A call to start () on a thread happens-before any of the actions in the started thread.
    • All the actions in a thread happen-before any and thread successfully returns from a join () to that thread.
    • The default initialization of any object Happens-before any other actions (other than default-writes) of a program.

Java Concurrency Programming Practice Note-happens-before rules

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.