Concurrency = the ability of a system to handle multiple tasks that are in progress at the same time (their lifetimes overlap), whether or not they physically execute simultaneously.
It is about dealing with many things at once (structure); parallelism is about doing many things at once (execution).
Concurrency vs. Parallelism
Aspect
Concurrency
Parallelism
Definition
Tasks make progress in overlapping time periods
Tasks execute literally at the same instant
Hardware
Possible on a single processor (interleaving)
Requires multiple processors/cores
Mechanism
Interleaving (time-sharing one CPU)
Overlapping (true simultaneous execution)
Goal
Structure / responsiveness
Speed-up / throughput
Interleaving – one processor rapidly switches among tasks → appears simultaneous (semi/pseudo concurrency).
Overlapping – multiple processors run tasks at the same real time (true concurrency).
Types of Concurrency
Semi (pseudo) concurrency – single processor, achieved by interleaving/time-slicing.
Sequential program – single thread of control; statements execute one after another in a defined order.
Concurrent program – multiple threads of control that may execute in parallel or be interleaved.
Concurrent system – the executing environment (hardware + OS + RTSS) that supports concurrent programs.
Concurrent program – the software describing the cooperating tasks.
Nature of Concurrent Systems
Tasks are (largely) independent but may need to cooperate and compete for shared resources.
Execution order between independent tasks is non-deterministic (not fixed).
The 6 Problems in Concurrent Programming
Violating mutual exclusion – two tasks in their critical section simultaneously → corrupted shared data.
Deadlock – tasks each hold a resource and wait for another's → all blocked forever.
Starvation / Lockout – a task is perpetually denied a needed resource.
Transient error – timing-dependent intermittent fault (hard to reproduce).
Busy waiting – a task wastes CPU cycles continuously polling instead of blocking.
Unfairness – resource allocation is not equitable among tasks.
Chapter 6 – Mechanisms to Support Concurrency
Two Forms of Concurrency
Hardware concurrency – true parallelism on multiprocessor/multi-core hardware.
Software concurrency – logical concurrency created by the OS/RTSS via interleaving on (possibly) one CPU.
Non-Determinism – the echo() Example
When two tasks call a shared echo() (read char → store → write) without protection, interleaved execution can lose or duplicate characters. This illustrates why unsynchronized access to shared data produces unpredictable (non-deterministic) results — the motivation for mutual exclusion.
Mutual Exclusion (MUTEX)
Ensures only one task accesses a shared resource / critical section at a time.
Critical Section (CS) structure:
entry section // request permission to enter
CRITICAL SECTION // access shared resource
exit section // release
remainder section // non-critical work
MUTEX requirements (a correct solution must satisfy):
Mutual exclusion – at most one task in the CS at any time.
Progress – if no task is in the CS, a waiting task must be allowed in (no needless blocking).
Bounded waiting – a task waits only a finite time (no starvation).
No assumptions about relative speed or number of processors.
3 Approaches to Satisfy Mutual Exclusion
Semaphore – integer variable with atomic wait()/P() and signal()/V() operations.
- Binary semaphore (0/1) → mutex lock.
- Counting semaphore → manages N instances of a resource.
Monitor – high-level construct encapsulating shared data + procedures; only one task may be active in the monitor at a time (mutual exclusion is automatic). Uses condition variables (wait/signal).
Message Passing – tasks synchronize/communicate by send/receive messages (no shared memory needed). Can be synchronous (blocking) or asynchronous (non-blocking).
Concurrent Programming (CP) Constructs
Fork/Join, cobegin/coend (or PAR), and explicit task/thread declarations mark statements to run concurrently.
Concurrent Programming Languages
Language
Concurrency Construct
Notes
Ada
task, PAR
Rendezvous model for task communication; designed for embedded/real-time.
OCCAM
SEQ, PAR, ALT
Based on CSP; designed for the transputer; channels for message passing.
Java
Thread class / Runnable interface
synchronized, wait(), notify(); monitors built in.
Concurrent C-- / BACI
cobegin … coend
Used in labs (BACI = Ben-Ari Concurrent Interpreter); semaphores.
Run-Time Support System (RTSS)
The layer beneath a concurrent program that manages tasks: creation, scheduling, context switching, synchronization.
Implements time-slicing – divides CPU time into small slices allocated to tasks in turn.
Context switch – saving one task's state (registers, PC, stack) and restoring another's.
Two Ways to Achieve Concurrency in Real-Time Systems
Concurrent language (Ada/OCCAM/Java) – concurrency is built into the language; RTSS provided by the language runtime.
Sequential language + RTOS – e.g., C + µC/OS-II; the RTOS kernel provides tasking. Tasks created via calls like:
c
OSTaskCreate(TaskFunc, &data, &TaskStk[STKSIZE], priority);
Chapter 7 – Concurrent Programming in Practice (BACI/jBACI)
jBACI – Java-based IDE/simulator for the BACI (Ben-Ari Concurrent Interpreter) system, used to write, compile, and visualize concurrent programs.
Supports Concurrent C-- and Concurrent Pascal dialects.
Key constructs practiced in labs:
cobegin p1(); p2(); coend; – run procedures concurrently.
Purpose: observe non-determinism, demonstrate race conditions, and verify that semaphores/monitors enforce mutual exclusion. Different runs of the same program can give different interleavings/outputs.
Chapter 8 – Real-Time Operating Systems (RTOS)
Definition
An RTOS is an OS that guarantees tasks complete within deterministic, predictable time bounds — correctness depends on both logical result and timing. It is an abstraction layer between application software and hardware.
Rate Monotonic (RM) vs. Earliest Deadline First (EDF)
Rate Monotonic (RM)
Earliest Deadline First (EDF)
Priority type
Fixed (static)
Dynamic
Priority rule
Shorter period T → higher priority
Earliest absolute deadline → higher priority
Assignment time
Offline (once)
At run time (recomputed)
Utilization bound
≤ n(2^(1/n) − 1) (≈0.693 as n→∞)
≤ 1 (100%)
Optimality
Optimal among fixed-priority schemes
Optimal among all schemes
Overhead
Low
Higher (deadline tracking)
Implementation
Simple, common in RTOS
More complex
Part 2 – Schedulability Analysis (SA)
Schedulability Analysis determines whether a given set of tasks can be successfully scheduled (every task completes by its deadline) under a specific algorithm.
A Schedulability Test (ST) validates that deadlines are met. (Scheduling with resource dependencies is NP-hard.)
3 Basic Approaches
Processor Utilization Analysis
Processor Workload Analysis
Response Time Analysis
1) Processor Utilization Analysis
ST 1 — EDF (Di ≥ Ti, periods integer multiples). Necessary & sufficient:
U = Σi=1n (Ci)/(Ti) ≤ 1
ST 2 — RM. Necessary & sufficient (sufficient bound, Liu & Layland):
U = Σi=1n (Ci)/(Ti) ≤ n(21/n - 1)
Utilization bound U(n) values:
n
U(n) bound
1
1.000
2
0.828
3
0.779
4
0.756
5
0.743
∞
0.693
Worked example — Mobile Robot (RM):
The mobile-robot case study: software drivers share hardware resources (8255 ports, ADC, motors, sensors) — the shared resources whose tasks are analysed below. Topic 8 – RT Scheduling Part 2 slides
Task
Tᵢ
Cᵢ
Cumulative U
U(n) bound
Schedulable?
MotorControlKanan
50
12
0.24
1.00
✅
MotorControlKiri
50
12
0.48
0.828
✅
AvoidBehavior
250
20
0.56
0.779
✅
MobileRobot
300
10
0.59
0.756
✅
HRI
500
125
0.84
0.743
❌ (0.84 > 0.743)
First 4 tasks → U = 0.59 ≤ 0.756 → schedulable.
Adding HRI (5th) → U = 0.84 > 0.743 → NOT schedulable by the utilization test.
⚠️ The utilization test is sufficient but not necessary for RM: failing it doesn't prove infeasibility — use Response Time Analysis for an exact answer.
2) Processor Workload Analysis
ST 3 — RM. Task Jᵢ is schedulable iff there exists a time instant t where the cumulative workload fits:
Wi(t) = Σk=1i Ck ⌈ (t)/(Tk) ⌉, 0 < t ≤ Ti
The inequality Wᵢ(t) ≤ t must hold for some t chosen from:
t = k Tj, j = 1… i, k = 1 … ⌊ (Ti)/(Tj) ⌋
If Di ≠ Ti, replace Tᵢ with min(Di, Tᵢ).
3) Response Time Analysis (RTA)
ST 4 — RM. Task i is schedulable if Rᵢ ≤ Dᵢ, where R is found by the recurrence:
Rix+1 = Ci + Σj ∈ hp(i) ⌈ (Rix)/(Tj) ⌉ Cj
hp(i) = set of tasks with higher priority than i (shorter periods under RM).
⌈ ⌉ = ceiling. The second term = interference from higher-priority tasks.
Iteration algorithm:
Step 1: first approximation a₀ = Σ Cⱼ (sum of C of task i and all higher-priority tasks).
Step 3: a₁ = a₀ = 42 (Cond. 3) → WCRT = 42 ms ≤ D = 200 ms → schedulable ✅
Full mobile-robot timing results (Di = Ti):
Task
Period T
WCET C
Rᵢ
Schedulable (R ≤ D)?
MobileRobot
50
1
1
✅
Motorctrl_left
50
20
21
✅
Motorctrl_right
50
20
41
✅
Subsumption
200
1
42
✅
Avoid
300
17
100
✅
Cruise
300
1
143
✅
Manrobotintf
500
16
200
✅
➡️ Even though the utilization test failed for the full set, RTA proves every task meets its deadline — RTA is exact (necessary & sufficient) while the utilization bound is only sufficient.
Worked example 2 — RTA convergence (task e₃: T=350, C=100, D=350; hp = e₁ T=100/C=40, e₂ T=150/C=40):