Embarcadero Delphi CodeRage 2025 Summary [Day1] Multithreading, Concurrency, Parallelism

CodeRage 2025 was an amazing event. I created a short summary of the CodeRage Day1 presentation for my future reference. Then I thought that it might be useful for others also so I will post it here. This is time consuming… if possible I will summarize the other days also.

The text is generated with some help from AI, so take it with a grain of salt (as usual)…

 


Session Overview

Cesar Homero, an Embarcadero MVP with 30+ years of Delphi experience, delivered a deep dive into multithreading and parallel programming in Delphi. His goal: help developers move from fear and complexity to mastery of concurrency and parallelism, leveraging modern tools like the Parallel Programming Library (PPL).

 

Key Concepts Explained

1. Concurrency vs Parallelism
* Concurrency: Managing multiple tasks logically, not necessarily executing them simultaneously. Example: A chef juggling tasks in a single kitchen.
* Parallelism: True simultaneous execution using multiple CPU cores. Example: Multiple chefs working at once.
* Asynchronous Execution: Non-blocking operations (e.g., REST API calls) that keep the UI responsive.

2. Classic Threads
* Powerful but low-level and error-prone.
* Manual management: `FreeOnTerminate`, synchronization, deadlock prevention.
* Expensive to create many threads (stack allocation, OS overhead).
* Suitable for long-lived background services, but not ideal for high-volume short tasks.

3. Modern Approach – Parallel Programming Library (PPL)
* Introduced in Delphi XE7.
* Provides thread pooling, task scheduling, and load balancing automatically.
* Developers focus on business logic, not thread orchestration.
* Scales across CPU cores efficiently.
* Key constructs: `TTask`, `TParallel.For`.

 

### Practical Demonstration

* Scenario: Fetching and displaying Embarcadero MVP data from a REST server.
* Architecture:
* REST server built with WebBroker.
* Client uses pipeline strategy pattern for clean, decoupled code.
* UI updates via callbacks without freezing.
* Comparison:
* Classic Threads: Works but creates 32 OS threads → high overhead.
* PPL Tasks: Cleaner code, faster start time, uses thread pool.
* Parallel.For: Aggressively reuses threads, best performance for large workloads (e.g., 250 requests).
* Responsiveness vs Speed:
* Parallel.For can saturate CPU → UI less fluid.
* Custom thread pool tuning recommended for balance.

 

Why PPL Wins

* Avoids manual infrastructure:
* Thread pool
* Scheduler
* Task queue
* Load balancing
* Reduces complexity and risk (deadlocks, race conditions).
* Verdict:
* Classic Threads: High complexity, manual management, high error risk.
* PPL: Low complexity, automatic management, optimized for multicore.

 

Future Vision

* Cesar teased a new library (working name: “Text”) for simplifying complex workflows:
* Declarative syntax for pipelines (e.g., download → parse → save → update UI).
* Automatic exception handling and result propagation.
* Planned release to the community soon.

 

Key Takeaways

* Evolution is not optional: Move from manual threads to PPL for cleaner, faster, safer code.
* Use threads only for permanent background services; for most tasks, PPL is superior.
* Full details, patterns, and code samples are in Cesar’s book “Delphi Multithreading” and GitHub repository.

See the rest of the sessions here.

Original video: https://www.youtube.com/watch?v=gZGx-c0rqA4

Leave a Comment

Scroll to Top