← All resources

SECJ 4423 – Real-Time Software Engineering

πŸ“˜ Detailed Study Notes (Chapters 5–9)

Companion to the concise summary. This version is organised by chapter β†’ sub-topic so you can revise one sub-topic at a time. Content is drawn only from the official lecture slides (Topic 5 Concurrency, Topic 5 Mechanisms, Topic 7 RTOS, Topic 8 RT Scheduling Parts 1 & 2, and the Utilization/Response-Time worked examples). Redundant duplicate slides were merged; every distinct topic/sub-topic is kept.


πŸ“‘ Master Table of Contents

Chapter 5 β€” Introduction to Concurrency

Chapter 6 β€” Mechanisms to Support Concurrency

Chapter 7 β€” Concurrent Programming in Practice (BACI / jBACI)

Chapter 8 β€” Real-Time Operating Systems (RTOS)

Chapter 9 β€” Real-Time Scheduling & Schedulability Analysis

Chapter 5 β€” Introduction to Concurrency

5.1 What is Concurrency

Need to memorise the definition. "A concurrent program has multiple threads of control that may execute in parallel or be interleaved."

5.2 Concurrency vs Parallelism

Aspect Concurrency Parallelism
Meaning Dealing with many tasks at once (overlapping lifetimes) Doing many tasks at the exact same instant
Processors Can be achieved on a single CPU Requires multiple CPUs / cores
Mechanism Interleaving Overlapping
Purpose Structure, responsiveness Speed-up, throughput

5.3 Interleaving vs Overlapping

5.4 Types of Concurrency (Semi vs True)

5.5 Process vs Thread

Process Thread
Definition A program in execution with its own address space A lightweight unit of execution inside a process
Memory Separate, isolated memory Shares the process's memory & resources
Overhead Heavy (expensive context switch) Light (fast create/switch)
Communication IPC (messages, pipes, shared mem set-up) Directly via shared variables (needs sync)
Term for "many" Multiprogramming Multithreading

5.6 Sequential vs Concurrent Program

5.7 Concurrent System vs Concurrent Program

5.8 Nature of Concurrent Systems

5.9 The Six Problems in Concurrent Programming

High-yield list β€” memorise all six with a one-line meaning.

  1. Violating Mutual Exclusion β€” two tasks enter their critical section together and access shared data at the same time β†’ corrupted/inconsistent data. This is the source of race conditions.
  2. Deadlock β€” tasks each hold a resource and wait for a resource held by another; a circular wait leaves them all blocked forever.
  3. Starvation / Lockout (slides: indefinite postponement) β€” a task is perpetually denied a resource it needs (others keep getting in first); it ends up waiting for an event that may never occur.
  4. Transient Error β€” a timing-dependent, intermittent fault; appears only for certain interleavings, hard to reproduce/debug.
  5. Busy Waiting β€” a task wastes CPU cycles continuously polling ("spinning") instead of blocking/sleeping until it can proceed.
  6. Unfairness β€” resource allocation among tasks is not equitable (some tasks systematically favoured).

Chapter 6 β€” Mechanisms to Support Concurrency

6.1 Two Forms of Concurrency

  1. Hardware concurrency β€” genuine parallelism from multiprocessor / multi-core hardware (overlapping).
  2. Software (logical) concurrency β€” created by the OS/RTSS via interleaving on possibly a single CPU.

6.2 Non-Determinism (the echo example)

6.3 Mutual Exclusion & the Critical Section

General structure of a task using a CS:

        entry section       // request permission to enter
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚ CRITICAL      β”‚    // access the shared resource
        β”‚ SECTION       β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        exit section        // release permission
        remainder section   // non-critical code

6.4 Requirements for a Correct MUTEX Solution

  1. Mutual exclusion β€” no two tasks simultaneously in the CS.
  2. Progress β€” if the CS is free, a task that wants to enter must be allowed in (a task outside the CS must not block others).
  3. Bounded waiting β€” a task waits only a finite time (no starvation).
  4. No assumptions about relative task speeds or the number of processors.

6.5 Three Approaches to Mutual Exclusion

Memorise the three + their key keyword/operation.

The slides give three broad ways to satisfy the MUTEX requirements:

  1. Software approaches β€” algorithms using only ordinary shared variables (e.g., Dekker's / Peterson's algorithm).
  2. Special-purpose machine instructions / hardware support β€” e.g., an atomic test-and-set instruction, or disabling interrupts.
  3. Operating-system / programming-language support β€” provides the three high-level mechanisms below: (a) semaphore, (b) monitor, (c) message passing.

The course focuses on the three OS/language mechanisms:

(a) Semaphore

(b) Monitor

(c) Message Passing

Mechanism Key operations Shared memory? Level
Semaphore wait/P, signal/V Yes Low
Monitor wait, signal (condition vars) Yes (encapsulated) High
Message passing send, receive No High

Code sketches β€” the same critical section, three ways:

(a) Binary semaphore (mutex lock):

semaphore mutex = 1;              // binary semaphore, initialised to 1

void task(void) {
    /* ... non-critical code ... */
    wait(mutex);                 // P β€” block if another task is inside
        /* CRITICAL SECTION: access the shared resource */
    signal(mutex);               // V β€” release; wake a waiting task
    /* ... remainder ... */
}

Counting semaphore (N interchangeable resource units):

semaphore slots = N;             // e.g. N identical buffers/printers
wait(slots);                     // take one unit (blocks when 0 left)
    /* use one unit of the resource */
signal(slots);                   // return the unit

(b) Monitor (mutual exclusion is automatic; coordinate with condition variables):

monitor BoundedBuffer {
    int count = 0;               // shared state, encapsulated
    condition notFull, notEmpty; // condition variables

    procedure insert(item x) {
        if (count == N) wait(notFull);   // block until space
        /* ... add x ... */  count++;
        signal(notEmpty);               // wake a waiting consumer
    }
    procedure remove() {
        if (count == 0) wait(notEmpty);  // block until item
        /* ... take item ... */ count--;
        signal(notFull);                // wake a waiting producer
    }
}   // only ONE task may be active inside the monitor at a time

(c) Message passing (no shared memory β€” communicate by copying):

// Producer task                 // Consumer task
item = produce();                receive(Producer, &item);   // blocks until a message arrives
send(Consumer, item);            use(item);

6.6 Concurrent Programming Constructs

A concurrent programming language must provide three fundamental facilities (from the slides):

  1. Expression of concurrent execution β€” a way to specify concurrent processes (how you launch them).
  2. Process synchronisation β€” how processes keep shared data consistent.
  3. Interprocess communication β€” how processes exchange information.

The constructs that provide them:

6.7 Concurrent Programming Languages

Language Concurrency support Communication model Notes
Ada task, PAR Rendezvous Designed for embedded / real-time.
OCCAM SEQ, PAR, ALT Channels (message passing, from CSP) Designed for the transputer.
Java Thread class / Runnable interface Shared memory + monitors synchronized, wait(), notify().
Concurrent C-- / BACI cobegin … coend Shared vars + semaphores Used in the labs (see Chapter 7).

6.8 Run-Time Support System (RTSS) & Time-Slicing

6.9 Two Ways to Achieve Concurrency

  1. Use a concurrent language (Ada / OCCAM / Java) β€” concurrency is built into the language; its runtime provides the RTSS.
  2. Sequential language + RTOS β€” e.g., C + Β΅C/OS-II; the RTOS kernel provides tasking. A task is created with a kernel call, e.g.: c OSTaskCreate(TaskFunc, /* pointer to task code */ &task_data, /* argument passed to task */ &TaskStk[SIZE], /* top of the task's stack */ priority); /* task priority */

Chapter 7 β€” Concurrent Programming in Practice (BACI / jBACI)

7.1 What is BACI / jBACI

7.2 Core Constructs

7.3 Counting Possible Outputs (Interleavings)

7.4 Fixing Non-Determinism with Semaphores

Chapter 8 β€” Real-Time Operating Systems (RTOS)

8.1 What is an RTOS

RTOS abstraction layer between Application Software and Hardware
The RTOS is an abstraction layer between application software and hardware, hiding processor details. Topic 7 – RTOS slides

8.2 RTOS vs General-Purpose OS

Four distinguishing points from the slides:

  1. Event-driven scheduling β€” an RTOS schedules tasks based on external events signalled by interrupts.
  2. Simple command interpreter β€” few/no utility programs (lean).
  3. Serves the controlled system, not human users β€” goal is to run the machine, not provide a rich UX.
  4. Deterministic timing β€” service times are strictly algebraic (no random timing components) to avoid delay and missed deadlines.
RTOS General-purpose OS
Goal Predictability / meeting deadlines Average throughput & fairness
Scheduling Priority-based, preemptive, event-driven Time-sharing / fair-share
Timing Deterministic, bounded Best-effort, variable
Users Serves the system it controls Serves human users
Size Small, lean kernel Large, many utilities

8.3 RTOS Structure (4 Elements)

Exam-relevant: name all four and what each does.

Element Role
Executive The overall controller of all programs. Directly controls scheduling, mutual exclusion, data transfer, and synchronisation. Acts as the manager.
Kernel Provides detailed facilities to the executive; called by the executive. Acts as the executor. (Executive = manager, kernel = executor.)
Application Program Interfaces (APIs) Interface through which application software requests OS services (self-explanatory).
Real-World Interfaces Software that handles the hardware of the system (talks to sensors/actuators/devices).
RTOS structure: Executive wraps the Kernel, with APIs and Real-world interfaces
The Executive (manager) surrounds the Kernel (executor); APIs face the application, Real-world interfaces face the hardware. Topic 7 – RTOS slides

8.4 RTOS Basic Services

Central service is Task Management; surrounding services:

  1. Task Management β€” lets developers split software into separate tasks ("chunks"); the main job is scheduling tasks at run time so they run in a timely, responsive way.
  2. Intertask Communication & Synchronisation β€” lets tasks pass information safely (without corruption) and coordinate/cooperate.
  3. Timers β€” services such as task delays and time-outs.
  4. Dynamic Memory Allocation (optional) β€” tasks "borrow" RAM chunks temporarily; can pass memory task-to-task to move large data quickly. Very small kernels omit this.
  5. Device I/O Supervisor (optional) β€” organising & accessing hardware devices.
RTOS basic services arranged around Task Management
RTOS basic services arranged around the central Task Management: Intertask Communication & Synchronisation, Timers, Dynamic Memory Allocation*, Device I/O Supervisor* (*optional). Topic 7 – RTOS slides

8.5 Example RTOSs

8.6 Β΅C/OS-II Introduction & Features

Features (memorise the list):

Feature Meaning
Portable Mostly ANSI C; only tiny CPU-specific part in assembly. Runs on 8/16/32/64-bit MCUs & DSPs (needs a stack pointer + push/pop of CPU registers).
ROMable Designed to be embedded in ROM as part of the product.
Scalable Use only the services you need β†’ reduces RAM/ROM (code & data space).
Preemptive multitasking Fully preemptive; always runs the highest-priority ready task. Manages up to 64 tasks (8 reserved for system).
Deterministic Execution time of every function/service is known & bounded.
Task stacks Each task has its own stack; sizes can differ; stack-checking feature measures actual usage.
Services Mailbox, queue, semaphore, time functions, etc.
Interrupt management Interrupts can suspend/resume tasks; can be nested up to 255 levels.
Robust & Reliable Field-proven in cameras, medical/musical instruments, engine controls, ATMs, industrial robots, etc.

8.7 Β΅C/OS-II Architecture

Layered top→bottom:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Application Software            β”‚   ← your tasks
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Β΅C/OS-II             β”‚  Β΅C/OS-II Config     β”‚   Software
β”‚  (MP-Independent)     β”‚  (Application-Specific)β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚      Β΅C/OS-II PORT  (Microprocessor-Dependent)β”‚  ← the porting layer
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚        Microprocessor   |    Timer            β”‚   Hardware
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
uC/OS-II architecture layers
Β΅C/OS-II architecture β€” Application Software over the MP-independent core + Configuration; the Port (MP-dependent) below; then Microprocessor + Timer hardware. Topic 7 – RTOS slides (cf. exam Figure A4.2)

Chapter 9 β€” Real-Time Scheduling & Schedulability Analysis

9.1 What is Scheduling

9.2 Task Model & Parameters

Symbol Name Meaning
T Period Time between successive releases of a periodic task
D (Relative) Deadline Time by which a task must finish after release (often D = T)
C Computation time (WCET) Worst-Case Execution Time
R Response time Release β†’ completion time (compare to D)
a / S Arrival / start time When the task is released
U Utilization Fraction of CPU a task needs = C / T

9.3 Task Types

9.4 Classification of Scheduling

Independent axes you can mix & match:

9.5 Basic Scheduling Policies

The slides (Cooling) list four basic policies: cyclic, time-slicing, task priorities, and using queues.

  1. Cyclic (cyclic executive) β€” a fixed, repeating timeline of slots; computed offline. Very predictable, but inflexible.
  2. Time-slicing / Round-Robin β€” equal CPU quanta rotated among ready tasks; fair but not deadline-aware.
  3. Task priorities (priority-based, preemptive) β€” always run the highest-priority ready task; it may preempt lower-priority tasks.
  4. Using queues β€” ready tasks are held in queues (e.g., one ready-queue per priority level, plus delay/timer queues); the scheduler dispatches from the head of a queue. This is the underlying mechanism the other policies are built on.

9.6 Rate Monotonic (RM)

9.7 Earliest Deadline First (EDF)

9.8 RM vs EDF

Rate Monotonic (RM) Earliest Deadline First (EDF)
Priority type Fixed / static Dynamic
Priority rule Shorter period β†’ higher priority Earliest deadline β†’ higher priority
Assigned Offline (once) At run time (recomputed)
Utilization bound n(2^(1/n) βˆ’ 1) (β†’ 0.693) 1 (100%)
Optimality Best among fixed-priority Best among all algorithms
Overhead Low, simple Higher (track deadlines)
Predictability under overload Degrades gracefully (low-priority misses) Can cascade (domino effect)

9.9 Priority Inversion & Priority Inheritance

Listed in the official RTS-concepts revision slide and used in problem-solving. Know the definitions and the fix.

9.10 Schedulability Analysis β€” Overview

9.11 ST1/ST2 β€” Processor Utilization Analysis

ST1 β€” EDF (Dα΅’ β‰₯ Tα΅’; periods integer multiples). Necessary & sufficient:

U = Ξ£i=1n (Ci)/(Ti) ≀ 1

ST2 β€” RM. Sufficient condition (Liu & Layland):

U = Ξ£i=1n (Ci)/(Ti) ≀ n(21/n - 1)

Utilization bound U(n):

n 1 2 3 4 5 β†’ ∞
U(n) 1.000 0.828 0.779 0.756 0.743 0.693

9.12 ST3 β€” Processor Workload Analysis

ST3 β€” RM. Task Jα΅’ is schedulable iff the cumulative workload catches up with time at some instant:

Wi(t) = Ξ£k=1i Ck ⌈ (t)/(Tk) βŒ‰, 0 < t ≀ Ti

The test passes if Wα΅’(t) ≀ t for some t taken from the set:

t = k Tj, j = 1… i, k = 1 … ⌊ (Ti)/(Tj) βŒ‹

9.13 ST4 β€” Response Time Analysis

ST4 β€” RM. Task i is schedulable if Rα΅’ ≀ Dα΅’, where Rα΅’ is the fixed point of:

Rix+1 = Ci + Ξ£j ∈ hp(i) ⌈ (Rix)/(Tj) βŒ‰ Cj

Iterative algorithm (memorise the 3 stop conditions):

Why RTA matters: it is exact (necessary & sufficient) for fixed-priority preemptive scheduling β€” so a task set that fails the utilization test may still be proven schedulable by RTA.


End of detailed notes. Every distinct sub-topic from the official Ch5–9 slides is included; duplicated slides were merged. For practice questions see MCQ_Bank.html; for exam-focus guidance see Exam_Topic_Map.md.