Tag Archives: ppl

Cancellable Parallel Tasks With Modal Progress Dialog, i.e., On Delphi’s TTask, PPL, ThreadPool, WaitAll with Progress and the rest

Quite some time has passed since working with multiple threads was introduced in Delphi (Delphi 2, way back in 1996). The TThread class at that time was a very lightweight wrapper around the Windows CreateThread function. Those “crazy” enough to venture into the world of parallel executing code aka multi-threaded applications know how (proper) writing and debugging of such applications can become frustrating (at least).

Some more time has passed, and in Delphi XE7, Parallel Programming Library (PPL) was introduced to simplify the efforts we have to invest when there are needs to have more tasks (a unit of work you need to get done) being executed at the same time / in parallel.

If, until “now”, you were afraid of even trying to understand how to implement parallel programming in your applications – you should not be so. I think each and every application can benefit in some way of code being executed in multiple treads. The “Using TTask from the Parallel Programming Library” from Embarcadero’s DocWiki has more than enough to get you started.

I’m not going to list examples when multi-threading can come handy – I’m certain all this is known. Also, I’m not going to repeat the words of so many who wrote articles and blog posts (here’s one and another) explaining what TTask is, how VCL is not thread safe and how you need to use some synchronization to update the UI of the application (being run in the main thread), how to wait for all tasks to finish their execution or how to speed up your loops using TParallel.For.

Continue reading