1 Real-time and safety-critical software
Safety-critical software is any software whose failure can cause serious harm, and in such systems correctness is not optional because lives, equipment, and the environment may depend on every decision the program makes. The chapter uses real incidents to show that failures can cascade from a small defect into major consequences, especially when software is embedded in complex systems of sensors, hardware, and human oversight. It emphasizes that these systems must be engineered with documented evidence of assurance, traceability, compliance, and verification rather than with “it seems to work” confidence.
The chapter then explains that many safety-critical systems are also real-time systems, meaning they must produce correct answers within bounded, provable time limits. In these settings, a late answer can be just as dangerous as a wrong one, because the physical world keeps moving while the program runs. Examples such as emergency braking, flight control, medical devices, industrial control, and railway signaling illustrate the same core challenge: the system must be both accurate and predictable, often under hard deadlines and adverse conditions.
Finally, the chapter makes the case for C++ as a dominant language in these domains because it offers performance, control, and an established ecosystem of certified tools and standards. At the same time, it highlights the language’s central paradox: C++ can support memory-safe designs, but it also allows dangerous memory errors, undefined behavior, and silent corruption to compile cleanly. To manage this, the chapter introduces a memory-safety triad of culture, knowledge, and discipline, supported by static analysis, sanitizers, reviews, and a structured learning process that will be used throughout the book.
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