Summary
In this chapter, we looked at the high-level multithreaded patterns that are supported (either directly or with a few simple wrappers) in Delphi’s Parallel Programming Library framework.
The chapter opened with a discussion of tasks and patterns—what they are and how they can be used to simplify multithreaded programming. As a bonus, I threw in a short treatise about variable capturing, which focused on only one problematic part—capturing a loop variable.
Then, we looked at how we can use tasks to split a loop into multiple parallel loops. We saw that there’s quite some work involved, particularly around task creation and setup. On the way, we also learned about the thread-pooling concept.
The last part of the very long section on tasks discussed exception handling. We learned that it is quite hard to correctly capture in the main thread exceptions that were raised inside a task and that it is better to catch all task exceptions explicitly...