Happens-before
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, the happened-before
relation Relation or relations may refer to: General uses * International relations, the study of interconnection of politics, economics, and law on a global level * Interpersonal relationship, association or acquaintance between two or more people * ...
(denoted: \to \;) is a relation between the result of two events, such that if one event should happen before another event, the result must reflect that, even if those events are in reality executed out of order (usually to optimize program flow). This involves
ordering Order, ORDER or Orders may refer to: * A socio-political or established or existing order, e.g. World order, Ancien Regime, Pax Britannica * Categorization, the process in which ideas and objects are recognized, differentiated, and understood * H ...
events based on the potential
causal relationship Causality is an influence by which one event, process, state, or object (''a'' ''cause'') contributes to the production of another event, process, state, or object (an ''effect'') where the cause is at least partly responsible for the effect, ...
of pairs of events in a concurrent system, especially
asynchronous Asynchrony is any dynamic far from synchronization. If and as parts of an asynchronous system become more synchronized, those parts or even the whole system can be said to be in sync. Asynchrony or asynchronous may refer to: Electronics and com ...
distributed systems Distributed computing is a field of computer science that studies distributed systems, defined as computer systems whose inter-communicating components are located on different computer network, networked computers. The components of a distribu ...
. It was formulated by
Leslie Lamport Leslie B. Lamport (born February 7, 1941) is an American computer scientist and mathematician. Lamport is best known for his seminal work in distributed systems, and as the initial developer of the document preparation system LaTeX and the author ...
. The happened-before relation is formally defined as the least
strict partial order In mathematics, especially order theory, a partial order on a set is an arrangement such that, for certain pairs of elements, one precedes the other. The word ''partial'' is used to indicate that not every pair of elements needs to be comparable; ...
on events such that: * If events a \; and b \; occur on the same process, a \to b\; if the occurrence of event a \; preceded the occurrence of event b \;. * If event a \; is the sending of a message and event b \; is the reception of the message sent in event a \;, a \to b\;. If two events happen in different isolated processes (that do not exchange messages directly or indirectly via third-party processes), then the two processes are said to be concurrent, that is neither a \to b nor b \to a is true. If there are other causal relationships between events in a given system, such as between the creation of a process and its first event, these relationships are also added to the definition. For example, in some programming languages such as Java, C, C++ or Rust, a happens-before edge exists if memory written to by statement A is visible to statement B, that is, if statement A completes its write before statement B starts its read. Like all strict partial orders, the happened-before relation is '' transitive'', ''
irreflexive In mathematics, a binary relation R on a set X is reflexive if it relates every element of X to itself. An example of a reflexive relation is the relation " is equal to" on the set of real numbers, since every real number is equal to itself. A ...
'' (and vacuously, '' asymmetric''), i.e.: * \forall a, b, c, if a \to b\; and b \to c\;, then a \to c\; (transitivity). This means that for any three events a, b, c, if a happened before b, and b happened before c, then a must have happened before c. * \forall a, a \nrightarrow a (irreflexivity). This means that no event can happen before itself. * \forall a, b, if a \to b then b \nrightarrow a (asymmetry). This means that for any two events a, b, if a happened before b then b cannot have happened before a. Let us observe that the asymmetry property directly follows from the previous properties: by contradiction, let us suppose that \forall a, b, we have a \to b\; and b \to a. Then by transitivity we have a \to a, which contradicts irreflexivity. The processes that make up a distributed system have no knowledge of the happened-before relation unless they use a
logical clock A logical clock is a mechanism for capturing chronological and causal relationships in a distributed system. Often, distributed systems may have no physically synchronous global clock. In many applications (such as distributed GNU make), if two pro ...
, like a
Lamport clock The Lamport timestamp algorithm is a simple logical clock algorithm used to determine the order of events in a distributed computer system. As different nodes or processes will typically not be perfectly synchronized, this algorithm is used to prov ...
or a
vector clock A vector clock is a data structure used for determining the partial ordering of events in a distributed system and detecting causality violations. Just as in Lamport timestamps, inter-process messages contain the state of the sending process's ...
. This allows one to design algorithms for
mutual exclusion In computer science, mutual exclusion is a property of concurrency control, which is instituted for the purpose of preventing race conditions. It is the requirement that one thread of execution never enters a critical section while a concurr ...
, and tasks like debugging or optimising distributed systems.


Byzantine Faults and the Impossibility of Detection

In distributed systems, the happened-before relation can be accurately tracked under crash failures using vector clocks, their variants, and other causality tracking mechanisms. However, under Byzantine faults, where processes may behave arbitrarily or maliciously, it is fundamentally impossible to detect the happened-before relation . The intuitive reasoning for this is that Byzantine processes can forge or manipulate metadata, making it impossible to determine true causal dependencies.


See also

*
Race condition A race condition or race hazard is the condition of an electronics, software, or other system where the system's substantive behavior is dependent on the sequence or timing of other uncontrollable events, leading to unexpected or inconsistent ...
*
Java memory model The Java memory model describes how threads in the Java programming language interact through memory. Together with the description of single-threaded execution of code, the memory model provides the semantics of the Java programming language. ...
*
Lamport timestamps The Lamport timestamp algorithm is a simple logical clock algorithm used to determine the order of events in a distributed computer system. As different nodes or processes will typically not be perfectly synchronized, this algorithm is used to pr ...
*
Logical clock A logical clock is a mechanism for capturing chronological and causal relationships in a distributed system. Often, distributed systems may have no physically synchronous global clock. In many applications (such as distributed GNU make), if two pro ...


Citations


References

* {{DEFAULTSORT:Happened-Before Logical clock algorithms Distributed computing problems Transitive relations