1 Real-time and safety-critical software
Real-world failures show why correctness alone is not enough when software controls physical systems. The chapter opens with examples such as the CrowdStrike outage and Therac-25 to show that a defect which is merely inconvenient in ordinary software can become catastrophic in safety-critical contexts. In these systems, software failures can cause injury, death, equipment damage, or cascading harm, so the software must be shown safe before deployment rather than merely debugged after the fact.
Safety-critical software is defined by stricter obligations than conventional software: it must be correct, independently assured, traceable to hazards and requirements, compliant with industry standards, and verified with rigorous testing and analysis. Many such systems are also real-time, meaning they must respond within provable time bounds, often under worst-case conditions. A late answer can be as dangerous as a wrong one, as illustrated by scenarios like automatic emergency braking, where the system must both decide quickly enough to act and accurately enough not to act when it should not.
The chapter then explains why C++ remains widely used in these domains despite its risks. It offers zero-overhead abstractions, deterministic control over memory and hardware access, and a mature ecosystem of compilers, static analyzers, and certification standards. But that control comes with a paradox: the language allows both safe and dangerous memory patterns, and defects such as buffer overflows, use-after-free, and undefined behavior can compile cleanly while still threatening the system. To write safer C++, the book emphasizes a disciplined process built on culture, knowledge, and consistent practice, supported by static analysis, dynamic sanitizers, code review, and a learning approach based on case studies that reveal defects, explain them deeply, and reinforce better design habits.
Five characteristics that distinguish safety-critical software from conventional software. Each one requires documented evidence, not just working code.
Mapping systems by real-time and safety-critical constraints. Systems in the top-right quadrant face both simultaneously: they must be correct and meet strict timing guarantees. Chemotherapy dosing and aircraft load-and-balance calculation are safety-critical but not real-time; a person checks the numbers before anyone acts on them, so timing is not a safety concern. Video streaming is real-time but not safety-critical; a buffer underrun is frustrating, not fatal.
The real-time safety-critical loop in an automatic emergency braking (AEB) system. The loop begins when an event occurs (a child in the road). Sensors capture the scene and feed data through preprocessing and fusion. The system detects objects, predicts trajectories, and calculates time-to-collision (TTC). If TTC falls below a safe threshold (for example, approximately 1.2 seconds), the system commands the actuators to brake. At 60 km/h, the vehicle travels 1.7 meters every 100 milliseconds, so a missed deadline means a potential collision.
The C++ safety paradox. C++ provides modern safe features and allows dangerous patterns simultaneously. Both paths lead to the same conclusion.
The memory safety triad. All three foundations must be present for the process to work. Remove any one, and memory bugs find their way through.
The memory safety process. Each stage exists to catch what the previous one cannot.
The Complete Learning Cycle (CLC)
Summary
- Real-time safety-critical systems must respond within strict deadlines; a missed deadline can be as dangerous as a wrong answer.
- C++ dominates safety-critical development because it offers deterministic execution, zero-cost abstractions, and a mature certification ecosystem.
- The C++ safety paradox: the language chosen to protect lives is also the leading source of life-threatening bugs.
- Memory safety is a concern for all C++ software; in safety-critical systems the same defects can cause irreversible harm.
- Building memory-safe C++ requires a systematic process: safe design patterns, static analysis, dynamic analysis, and code review.
- Safe C++ depends on knowledge, discipline, and culture. This book provides the first.
Memory Safe C++ ebook for free