Race Conditions and Hazards

Race Condition

Definition

A race condition is the condition where a system's substantive behaviour is dependent on the sequence or timing of other uncontrollable events.

Race conditions can occur especially in logic circuits, concurrent programming, and distributed computing.

Hazard

Definition

A hazard it a momentary unwanted switching transient at a circuits output (i.e glitch) due to uneven propagation delays along different paths of a combinational circuit.

In Electronics

See Hazard Free Circuits.

Example

Consider the circuit:

The result of will never be true, right? Wrong. Since the NOT gate has a propagation delay, there is a brief moment when both inputs to the AND gate are true, before the NOT gate can change its output. This leads to the AND gate outputting a short pulse.

This is an example of a hazard.

Critical and Non Critical Forms

Definition

A critical race condition occurs when the order in which internal variables change determines the eventual state the state machine will end up in

Likewise, a non-critical race condition is where order doesn't matter.

Static, Dynamic, and Essential Forms

Definition

A static race condition occurs when a signal and its negation are combined

A dynamic race condition occurs when there are multiple transitions when only one was intended

An essential race condition occurs when an input has two transitions in less than the total feedback propagation time

Design techniques such as K-maps help with discovering and eliminating race conditions.

In Software

A race condition can arise when a program has multiple code paths that are executing at the same time. If these paths take a different amount of time than expected, this can create bugs due to unanticipated behaviour.