Chapter 1: Real-time and safety-critical software
The section uses the CrowdStrike outage to contrast a recoverable software failure with the potentially irreversible consequences of memory errors in safety-critical systems.
After this chapter you will be able to
- Safety-critical failure consequences. Distinguish the recoverable operational and financial harm of the Falcon outage from the potentially physical consequences of the same kind of error in safety-critical software.
- Safety criticality and harm. Explain what makes a system or component safety-critical and why non-critical components may still matter to its safety.
- Correctness under degraded conditions. Explain what correctness requires in normal operation and when faults or degraded conditions occur.
- Safety assurance and traceability. Explain why working software needs a safety case and how traceability supports an auditable safety argument.
- Compliance and verification methods. Describe the role of industry standards and the kinds of verification used for safety-critical software.
- Safety and timing intersection. Explain how real-time safety-critical software combines safety-critical correctness with bounded, verifiable response times, and distinguish it from systems subject to only one constraint.
- Hard real-time deadlines. Distinguish hard from soft real-time deadlines and explain why a hard deadline is defined by the consequence of missing it rather than its length.
- Worst-case timeliness argument. Explain why timeliness is established separately from computational correctness and why the timing argument considers the hardware under worst conditions.
- Braking correctness and timeliness. Explain why the automatic emergency braking system must act both quickly enough and correctly enough, including the hazards of late and inappropriate braking.
- Shared correctness and timing constraints. Explain how safety-critical systems across industries must be both correct and timely, using an example from the section.
- Continuous hazard identification. Explain why hazard identification starts before design and continues after systems are deployed.
- Verification beyond expected conditions. Distinguish functional testing from safety verification in terms of the conditions they examine and the role of evidence.
- Predictable response over speed. Explain why predictable response time can be preferable to faster usual performance in a safety-critical system.
- Graceful degradation under failure. Explain why safety-critical systems should be designed to degrade gracefully when failures or unexpected inputs occur.
- Combined case for C++. Explain why engineers choose C++ for safety-critical systems despite its complexity and subtle dangers.
- Zero-cost abstraction efficiency. Explain zero-cost abstractions using std::array indexing as the section's example.
- Memory cleanup timing control. Explain why unpredictable garbage-collection pauses matter in a safety-critical system and what timing control C++ provides instead.
- Stack allocation timing bounds. Describe the timing of stack allocation, its page-fault qualification, and how heap addresses differ.
- Determinism and timing predictability. Distinguish deterministic results from predictable execution time, and explain why modern hardware complicates worst-case timing bounds.
- Storage costs and timing structure. Explain how stack and heap storage differ in the predictability of allocation costs, and describe the approaches and language structure discussed for managing timing.
- Timing bounds for safety. Explain why bounded operation timing is needed for timely safety-critical response, using the pacemaker example.
- Mature C++ safety ecosystem. Explain why C++’s field-tested tools and established certification ecosystem matter in safety-critical development.
- Memory control and risks. Explain the benefits and risks of direct memory access and manual memory management in C++.
- Undefined behavior and optimization. Explain what undefined behavior means in C++ and why code exhibiting it can behave unexpectedly.
- Delayed and silent failures. Describe how memory corruption and leaks can escape initial testing and cause failures later.
- C++ safety paradox. Explain how C++ can offer memory-safe tools while still allowing dangerous code to compile, and relate this to its flexibility.
- Memory safety triad. Explain the roles of culture, knowledge, and discipline in sustaining memory-safe C++.
- Sensor label boundary design. Trace the failures for 32- and 33-character sensor labels and describe a design that prevents them.
- Dynamic boundary testing. Explain how ASan and boundary value tests expose the sensor-label defect and why passing short-label tests is insufficient.
- Layered process and review. Explain how design, static analysis, dynamic analysis, and human review form a layered process that still depends on disciplined people.
- Discovery and technical exploration. Describe how a case study begins with defect discovery and then explores the defect technically.
- Reimplementation and reflective cycle. Explain how guided reimplementation and reflection complete the cycle and prepare the reader for future case studies.
- Example development toolchain. Describe the tools needed to build the examples and the analysis tools used to catch memory bugs.
- Sample compliance and deviations. Explain how the code samples are checked against coding standards and what the repository’s reports and deviation records provide.
Section by section
Introduction
The section uses the CrowdStrike outage to contrast a recoverable software failure with the potentially irreversible consequences of memory errors in safety-critical systems.
- CrowdStrike out-of-bounds failure: Trace how a mismatch in input fields led to the CrowdStrike Falcon crash and describe its operational effects.
Why it matters: The incident shows how an out-of-bounds read can disrupt services far beyond the software itself. - Safety-critical failure consequences: Distinguish the recoverable operational and financial harm of the Falcon outage from the potentially physical consequences of the same kind of error in safety-critical software.
Why it matters: The potential for irreversible physical harm makes correct and timely execution crucial in safety-critical systems.
Key terms: out-of-bounds read, runtime bounds check, IPC template, content interpreter, safety-critical software, silent data corruption, correct and timely execution
1.1 Defining safety-critical software
This section defines safety-critical software and explains the demands and development characteristics that distinguish it from conventional software.
- Safety criticality and harm: Explain what makes a system or component safety-critical and why non-critical components may still matter to its safety.
Why it matters: This definition helps you identify where safety arguments are needed, even within a mixed-criticality system. - Operational reliability and interactions: Describe why software that works in isolation may still fail in a safety-critical system, and state the reliability conditions such systems must meet.
Why it matters: This shows why isolated functional success is not enough to establish dependable system behavior. - Correctness under degraded conditions: Explain what correctness requires in normal operation and when faults or degraded conditions occur.
Why it matters: Safety depends on how software behaves when conditions are not ideal, not just when everything works. - Safety assurance and traceability: Explain why working software needs a safety case and how traceability supports an auditable safety argument.
Why it matters: A safety claim must be supported by evidence that can be followed from hazards to implementation and tests. - Compliance and verification methods: Describe the role of industry standards and the kinds of verification used for safety-critical software.
Why it matters: Standards and verification provide disciplined ways to substantiate safety requirements.
Key terms: safety-critical, cascading failures, criticality, reliability targets, harsh environments, correctness, degraded operating conditions, safe state, assurance, safety case
1.2 Defining real-time safety-critical software
This section defines real-time safety-critical software through its correctness and timing requirements, hard deadlines, and an automatic emergency braking example.
- Safety and timing intersection: Explain how real-time safety-critical software combines safety-critical correctness with bounded, verifiable response times, and distinguish it from systems subject to only one constraint.
Why it matters: This distinction explains why a correct answer can still fail in a safety-critical system. - Hard real-time deadlines: Distinguish hard from soft real-time deadlines and explain why a hard deadline is defined by the consequence of missing it rather than its length.
Why it matters: The difference determines whether an occasional late response is acceptable or a failure. - Worst-case timeliness argument: Explain why timeliness is established separately from computational correctness and why the timing argument considers the hardware under worst conditions.
Why it matters: A computation that usually runs quickly is not enough to establish a guaranteed deadline. - Emergency braking decision chain: Trace the automatic emergency braking example from sensor data through environmental assessment and decision to brake actuation.
Why it matters: The example makes concrete the sequence that must produce a timely safety decision. - Braking correctness and timeliness: Explain why the automatic emergency braking system must act both quickly enough and correctly enough, including the hazards of late and inappropriate braking.
Why it matters: A safe response requires avoiding both a missed intervention and an unjustified one.
Key terms: real-time safety-critical software, correctness, time bounds, hard real-time, soft real-time, deadline, timeliness, worst conditions, automatic emergency braking, sensor fusion
1.3 Different industries, same challenge
This section shows how industries share correctness and timing constraints and outlines common safety practices despite differing standards.
- Shared correctness and timing constraints: Explain how safety-critical systems across industries must be both correct and timely, using an example from the section.
Why it matters: Safety depends on getting the right response in time, not just producing a correct response eventually. - Continuous hazard identification: Explain why hazard identification starts before design and continues after systems are deployed.
Why it matters: Hazards must shape the design from the start and continue to inform it as experience reveals new risks. - Verification beyond expected conditions: Distinguish functional testing from safety verification in terms of the conditions they examine and the role of evidence.
Why it matters: Safety verification must look beyond the cases the design anticipated and provide evidence of that search. - Predictable response over speed: Explain why predictable response time can be preferable to faster usual performance in a safety-critical system.
Why it matters: An occasional long delay can undermine safety even when most responses are very fast. - Graceful degradation under failure: Explain why safety-critical systems should be designed to degrade gracefully when failures or unexpected inputs occur.
Why it matters: Designing for failure helps prevent component faults or unexpected inputs from becoming catastrophes.
Key terms: correct and fast, deadline, signalling, hazards, fielded systems, design, functional testing, safety verification, evidence, predictability
1.4 The case for C++
This section explains why C++ remains a common choice for safety-critical systems despite its complexity and the availability of safety-oriented alternatives.
- Combined case for C++: Explain why engineers choose C++ for safety-critical systems despite its complexity and subtle dangers.
Why it matters: This combination explains why C++ remains attractive even in demanding safety-critical applications. - Safety oriented language alternative: Distinguish Ada's safety-oriented design from the reasons C++ remains in use.
Why it matters: The comparison shows that C++ is not the only defensible language choice for safety-critical work.
Key terms: performance, predictability, ecosystem, Ada, built-in safety features, safety-critical applications
1.4.1 Performance without overhead
This section explains how C++ provides efficient abstractions, control over memory timing, and direct hardware access for real-time safety-critical systems.
- Zero-cost abstraction efficiency: Explain zero-cost abstractions using std::array indexing as the section's example.
Why it matters: Efficient abstractions let you write clearer code without necessarily sacrificing performance. - Memory cleanup timing control: Explain why unpredictable garbage-collection pauses matter in a safety-critical system and what timing control C++ provides instead.
Why it matters: The timing of memory cleanup can affect whether a safety-critical operation completes when it must. - Stack allocation timing bounds: Describe the timing of stack allocation, its page-fault qualification, and how heap addresses differ.
Why it matters: Understanding the bounds and exceptions helps avoid treating fast allocation as an unconditional timing guarantee. - Direct hardware access boundaries: Distinguish C++ facilities for direct hardware access from the implementation-specific definitions of registers and interrupts.
Why it matters: Direct hardware access is useful, but the details of a particular device are not portable standard C++.
Key terms: zero-cost abstractions, std::array, raw array, garbage collection, destruction, unpredictable pause, stack pointer, stack frame, page fault, heap
1.4.2 Deterministic execution
This section explains why bounded execution time matters in safety-critical C++ and how storage choices affect timing predictability.
- Determinism and timing predictability: Distinguish deterministic results from predictable execution time, and explain why modern hardware complicates worst-case timing bounds.
Why it matters: A correct result is not enough if the program cannot be relied on to finish in time. - Storage costs and timing structure: Explain how stack and heap storage differ in the predictability of allocation costs, and describe the approaches and language structure discussed for managing timing.
Why it matters: Storage choices affect whether allocation costs can be bounded for a live system. - Timing bounds for safety: Explain why bounded operation timing is needed for timely safety-critical response, using the pacemaker example.
Why it matters: A timing bound connects code behavior to a demonstrably timely and certifiable safety-critical response.
Key terms: determinism, predictability, worst-case execution time, WCET, stack storage, heap storage, allocator, construction, destruction, template instantiation
1.4.3 Industry maturity
This section explains how C++’s established safety-critical tooling, standards, and existing codebases support its use without proving that the language is safer.
- Mature C++ safety ecosystem: Explain why C++’s field-tested tools and established certification ecosystem matter in safety-critical development.
Why it matters: A mature toolchain and documented process help teams demonstrate safety, beyond achieving performance and determinism. - Adoption context and limits: Describe how Rust’s developing safety ecosystem and existing C++ codebases affect the practical context for choosing C++, while distinguishing maturity from language safety.
Why it matters: Practical adoption depends on existing infrastructure and teams, which is different from proving a language safer.
Key terms: certified compilers, qualified static-analysis tools, coding standards, MISRA, AUTOSAR, CERT, certified toolchains, Safety-Critical Rust Consortium, codebase
1.5 Memory safety challenges
This section explains how C++ memory control can lead to undefined behavior, leaks, and silent failures that evade initial testing.
- Memory control and risks: Explain the benefits and risks of direct memory access and manual memory management in C++.
Why it matters: The same control that makes C++ useful also places memory-safety responsibilities on the programmer. - Undefined behavior and optimization: Explain what undefined behavior means in C++ and why code exhibiting it can behave unexpectedly.
Why it matters: Code that compiles and appears to work can still behave unpredictably when it contains undefined behavior. - Delayed and silent failures: Describe how memory corruption and leaks can escape initial testing and cause failures later.
Why it matters: A clean initial run does not rule out memory problems that emerge only over time.
Key terms: direct memory access, manual memory management, memory leak, undefined behavior, signed integer overflow, null pointer dereference, uninitialized variables, silent memory corruption, buffer overflow
1.6 The C++ safety paradox
This section explains the C++ safety paradox: the flexibility that makes C++ broadly useful also allows memory-unsafe code to compile.
- C++ safety paradox: Explain how C++ can offer memory-safe tools while still allowing dangerous code to compile, and relate this to its flexibility.
Why it matters: This distinction explains why choosing C++ and using some safe features does not by itself guarantee memory safety. - Language safety enforcement contrasts: Distinguish C++'s provision of safety tools from the enforcement described for Rust and Ada.
Why it matters: The comparison clarifies the difference between making safety possible and enforcing it.
Key terms: C++ safety paradox, memory-safe code, flexibility, borrow checker, runtime checks, memory bugs
1.7 C++ memory safety triad
This section introduces the memory safety triad and traces a sensor-label defect through design, static analysis, dynamic analysis, and review.
- Memory safety triad: Explain the roles of culture, knowledge, and discipline in sustaining memory-safe C++.
Why it matters: Knowing the triad helps you see why individual expertise alone cannot sustain memory safety. - Sensor label boundary design: Trace the failures for 32- and 33-character sensor labels and describe a design that prevents them.
Why it matters: The example shows why preventing a write overflow is not enough when a C string also needs a terminator. - Static analysis and rulesets: Distinguish static rule enforcement from approximate reasoning about values, and describe how a ruleset can flag the unbounded copy.
Why it matters: This distinction helps you interpret an analyzer warning and understand why a team must decide how to handle it. - Dynamic boundary testing: Explain how ASan and boundary value tests expose the sensor-label defect and why passing short-label tests is insufficient.
Why it matters: A clean sanitizer run is useful only for the paths and inputs the tests actually exercised. - Layered process and review: Explain how design, static analysis, dynamic analysis, and human review form a layered process that still depends on disciplined people.
Why it matters: Layering checks helps catch missed defects, but rushing or skipping a phase weakens the protection.
Key terms: culture, knowledge, discipline, memory safety triad, std::copy, null-terminated C string, boundary condition, kMaxLabelLength, static analysis, rule enforcement
1.8 The complete learning cycle (CLC)
This section explains the Complete Learning Cycle for learning to recognize and address C++ defects through case studies.
- Discovery and technical exploration: Describe how a case study begins with defect discovery and then explores the defect technically.
Why it matters: Finding and investigating a defect helps you recognize similar problems later. - Reimplementation and reflective cycle: Explain how guided reimplementation and reflection complete the cycle and prepare the reader for future case studies.
Why it matters: Applying and reflecting on a solution helps turn a single case study into better defect-spotting instincts.
Key terms: Complete Learning Cycle, Defect Discovery, Deep Technical Exploration, Guided Reimplementation, Reflection
1.9 Tools and environment
This section outlines the tools, compliance checks, and C++ versions used to work through the book’s examples.
- Example development toolchain: Describe the tools needed to build the examples and the analysis tools used to catch memory bugs.
Why it matters: These tools let you build the examples and investigate memory bugs as you work through the book. - Sample compliance and deviations: Explain how the code samples are checked against coding standards and what the repository’s reports and deviation records provide.
Why it matters: The reports let you inspect how examples fare against the standards and why any rules were waived. - Language versions and experimentation: State the C++ version targeted by the case studies and describe the online option for experimenting with code.
Why it matters: Knowing the target version and online option helps you choose an environment for trying the examples.
Key terms: C++ compiler, Bazel, Git, Clang-Tidy, static analysis, dynamic analyzers, Parasoft C/C++test, MISRA C++:2023, SEI CERT C++ Coding Standard, compliance reports
1.10 Summary
Where this is used later
- The safety standards (chapter 2) · The safety standards section develops the industry-specific standards introduced here.
- C++ coding guidelines in practice (chapter 2) · The coding guidelines section builds on the need for disciplined safety-critical development.
- Spatial memory safety (The “where” question) (chapter 2) · Distinguishes violations involving where memory is accessed.
- Temporal memory safety (The “when” question) (chapter 2) · Distinguishes violations involving when memory is accessed.
- (chapter intro) (chapter 2) · The earlier discussion of C++ memory safety challenges provides context for compiler limitations.
- Type of memory safety violations (chapter 2) · Develops the discussion of memory safety violations.
- The two categories of impacts (chapter 2) · Develops the discussion of the impacts of memory safety violations.
- Toward compiler-enforced memory safety (chapter 2) · The distinction between offering and enforcing safety provides context for compiler-enforced memory safety.
Concepts explained in this chapter
- memory safetyThe property that a program's memory operations do not cause errors such as out-of-bounds access or corruption.
- safety-critical applicationA system whose failure could cause serious harm, including harm propagated through connected systems.
- dynamic analysisAnalysis of software behavior by executing the software and observing its runtime properties.
- static analysisStatic analysis examines software without executing it to identify properties, defects, or rule violations.
- safe-programming disciplineSafe-programming discipline is the consistent application of safe practices, including under schedule pressure.
- safety cultureA safety culture is a shared team and organizational commitment to prioritizing safety and best practices.
- predictabilityPredictability is the property of an operation having an execution time that can be bounded in advance.
- style guideA set of rules specifying what software source code may contain and what it must not do.
- use-after-free errorUse-after-free is an error in which a program accesses memory after it has been deallocated.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
