Overview

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.
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.
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 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 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 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 memory safety process. Each stage exists to catch what the previous one cannot.
The Complete Learning Cycle (CLC)
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.

FAQ

What makes software safety-critical?Software is safety-critical when its failure could cause serious harm, such as death, injury, equipment destruction, environmental damage, or cascading failures in connected systems. In these systems, safety must be demonstrated before release, not just observed after deployment.
Why is timing part of correctness in real-time safety-critical software?Because a correct answer delivered too late can be just as dangerous as a wrong one. In real-time safety-critical systems, the physical world keeps changing while the software runs, so missing a deadline can make the output useless or unsafe.
How is real-time safety-critical software different from other safety-critical software?It must satisfy both safety and strict time bounds. For example, chemotherapy dosing is safety-critical but not necessarily real-time, while an automatic emergency braking system must be both correct and fast enough to act before a collision occurs.
Why are hard real-time deadlines so important?Hard real-time systems must meet their deadlines every time, not just on average. In these systems, a missed deadline counts as a failure because late action can directly lead to harm.
Why does C++ remain popular in safety-critical development?C++ offers performance, predictability, and a mature ecosystem. It provides zero-cost abstractions, strong control over memory and hardware, and decades of industry use, which makes it attractive for systems that must be both fast and reliable.
What is the C++ safety paradox?C++ provides tools for writing safe code, but it also allows dangerous patterns that the compiler will not stop. That means memory-safe and memory-unsafe approaches can coexist in the same codebase, so safety must be enforced deliberately.
What are the main memory safety risks in C++?The major risks include out-of-bounds access, use-after-free, null pointer dereference, uninitialized reads, memory leaks, and silent memory corruption. Many of these compile cleanly and may only fail later in unpredictable ways.
What is the memory safety triad described in the chapter?The triad is culture, knowledge, and discipline. A team needs a safety-focused culture, an understanding of common memory bugs, and the discipline to apply safe practices consistently, especially under deadline pressure.
What tools are used to build memory-safe C++?The chapter highlights static analysis, dynamic analysis tools like AddressSanitizer, UndefinedBehaviorSanitizer, and ThreadSanitizer, plus coding standards such as MISRA C++ and SEI CERT. These tools help detect defects, but they must be used within a disciplined process.
What is the Complete Learning Cycle (CLC) in this book?The CLC is a four-stage learning framework: defect discovery, deep technical exploration, guided reimplementation, and reflection. It is designed to help readers find defects themselves, understand why they happen, practice safer solutions, and apply the lessons to their own code.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Memory Safe C++ Memory Safe C++ ebook for free
Close
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Memory Safe C++ Memory Safe C++ ebook for free