javaconcurrencyhappens-before

"Partial Ordering" and Happens-before relation java


I am reading Java Concurrency in Practice

I am confused with the specific explanation regarding happens-before relationship.

It states that,

operations are ordered by a partial ordering called happens-before

What exactly does this mean by "partial ordering"?

(There is an explanation in the book but its not clear to me )


Solution

  • Partial Ordering means that not every pair of operations has the relation happens-before.

    Actually, the fact that not every pair of operations has that relation enables you to perform operations concurrently.

    For example, suppose you have operations A, B, C & D.

    We can define a partial ordering: A must happen before B and C.

    Then A and B have the happens-before relation, as do A and C. However, A and D don't have that relation, so D can be executed either before A, after A or while A is being executed.

    If, on the other hand, happens-before was a full ordering, such as A happens-before B happens-before C happens-before D (note that in this case, for each pair of operations you know which one happens-before the other, hence it is a full ordering), then the execution of the operations would have to be serial, and no concurrency would be possible.