UNIT 13 · BUILDING RELIABLE SYSTEMS
Concurrency and Real-Time Design
Do many things at once, and prove each one is on time.
Once firmware has more than one job, the hard questions are no longer about any single job but about how the jobs share the processor: who runs next, who waits, for how long, and what happens when two of them touch the same data. The answers range from a switch statement in a loop to a preemptive RTOS, and each step up buys shorter latency at the price of new ways to fail.
The unit in six ideas
- 1A state machine lists states, events, transitions and actions; one table shows the whole behaviour and every ignored event.
- 2A cooperative scheduler is a task table, a timer interrupt that only marks tasks due, and a loop that runs the most urgent due task to completion.
- 3A task is a function with its own stack and priority, so it can be preempted anywhere and resumed with its locals intact.
- 4Blocking on a kernel object costs no CPU; every blocking call should have a deliberate timeout.
- 5Any preemption point can split a read-modify-write or check-then-act sequence; protect the whole sequence or give the data one owner.
- 6Describe each task by worst-case execution time C, period T and deadline D; U = Σ C/T above 1 means some deadline must be missed.
Lessons
State Machines and Event-Driven Design
How do you design firmware so that impossible situations cannot be reached?
Cooperative Scheduling and Superloops
How far can you get with a timer, a table and a loop, and where exactly does it stop working?
Tasks, Context Switching, and Scheduling
What if the scheduler could stop the long job in the middle, run the sampler, and resume the long job exactly where it was, without the long job being written any differently?
Queues, Semaphores, and Mutexes
Which one is right, and what goes wrong with the others?
Race Conditions, Deadlocks, and Priority Inversion
How can a task that uses no shared data delay one that is more important than it?
Deadlines, Execution Budgets, and Timing Analysis
How do you show, before shipping, that every deadline will be met?