Glossary · Automation software engineering and architecture
Race condition
Also known as: Race hazard, Data race
German: Wettlaufsituation
In concurrent software, a race condition is a defect in which the result depends on the uncontrolled timing or order of concurrent operations, for example two tasks reading and writing shared data without synchronization.
- Software engineering
In one sentence
A race condition is a defect whose result depends on the uncontrolled timing of concurrent operations on shared data.
Example
The HMI task writes a new setpoint in two steps while the control task reads it in between, so the controller briefly uses a mixed, invalid value.
How it applies
- Engineering: Race conditions are prevented through Mutual exclusion, atomic operations or by design, for example by giving each piece of data exactly one writer. In PLCs, data exchanged between tasks of different cycle times is a typical source.
- Verification: Races are intermittent and often vanish under a debugger. Code review, Static code analysis and stress tests are more effective than functional tests alone.
- Documentation: Problem reports for intermittent faults should record timing context. PLC programming guidelines should explain how to exchange data consistently between tasks.
Race condition (software) vs. race hazard (hardware)
In digital circuits, a race hazard is a glitch caused by signals arriving at different times. In software, a race condition concerns concurrent tasks. The principle is similar; the countermeasures differ.