javamultithreadingjava-memory-modeljls

Why is the sufficient set of synchronization edges unique and how to build it?


JLS states this:

A set of synchronization edges, S, is sufficient if it is the minimal set such that the transitive closure of S with the program order determines all of the happens-before edges in the execution. This set is unique.

Why is the sufficient set unique?

How can we determine which synchronization edges are in the sufficient set and which aren't?


Solution

  • I found the answers.

    Why is the sufficient set unique?

    According to the JLS happens-before is a strict partial order:

    The happens-before order is given by the transitive closure of synchronizes-with edges and program order. It must be a valid partial order: reflexive, transitive and antisymmetric.

    That means happens-before can be represented as a directed acyclic graph (DAG):

    Strict partial orders correspond directly to directed acyclic graphs (DAGs)

    According to the wiki:

    The transitive reduction of a DAG is the graph with the fewest edges that has the same reachability relation as the DAG. It has an edge u → v for every pair of vertices (u, v) in the covering relation of the reachability relation ≤ of the DAG. It is a subgraph of the DAG, formed by discarding the edges u → v for which the DAG also contains a longer directed path from u to v. Like the transitive closure, the transitive reduction is uniquely defined for DAGs.

    This "transitive reduction" is "the sufficient minimal set" in the question.

    How can we determine which synchronization edges are in the sufficient set and which aren't?

    From the wiki:

    It is a subgraph of the DAG, formed by discarding the edges u → v for which the DAG also contains a longer directed path from u to v.