HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
, the happened-before relation (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 events based on the potential causal relationship of pairs of events in a concurrent system, especially asynchronous
distributed systems A distributed system is a system whose components are located on different networked computers, which communicate and coordinate their actions by passing messages to one another from any system. Distributed computing is a field of computer sci ...
. It was formulated by
Leslie Lamport Leslie B. Lamport (born February 7, 1941 in Brooklyn) 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 happened-before relation is formally defined as the least strict partial order 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'' and '' antisymmetric'', 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, where a \neq b, if a \to b then b \nrightarrow a (antisymmetry). This means that for any two distinct events a, b, if a happened before b then b cannot have happened before a. The processes that make up a distributed system have no knowledge of the happened-before relation unless they use a logical clock, like a Lamport clock or a vector clock. 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 concurrent ...
, and tasks like debugging or optimising distributed systems.


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. It becomes a bug when one or more of t ...
* Java Memory Model * Lamport timestamps * Logical clock


References

{{DEFAULTSORT:Happened-Before Causality Logical clock algorithms Distributed computing problems