2020-03-20

Thread Happens before relation

What is Happens before relation?

  • Sequential order: Each action in a thread happens-before every action in that thread that comes later in the program’s order.
  • Unlock → Lock: An unlock (synchronized block or method exit) of a monitor happens-before every subsequent lock (synchronized block or method entry) of that same monitor.
  • Volatile writes: 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.
  • A call to start on a thread happens-before any action in the started thread.
  • All actions in a thread happen-before any other thread successfully returns from a join on that thread.
  • Happens-before relation is transitive.

Atomic variables


The java.util.concurrent.atomic package defines classes supporting atomic operations on single variables.
All classes of get and set operations.
Like volatile variables’ write operation, the set operation has an happens-before relation with the corresponding get operation





No comments:

Post a Comment