Task parallelism¶
Category: Parallelism · Status: stub · Lessons: chapter 07, Parallelism
One line: Different tasks, possibly doing different things, running at the same time on different cores.
How it connects¶
flowchart LR
n_data_parallelism["Data parallelism"]
n_fork_join["Fork-join"]
n_parallelism["Parallelism"]
n_task_parallelism["Task parallelism"]
n_data_parallelism ---|vs| n_task_parallelism
n_fork_join -->|is a| n_task_parallelism
n_task_parallelism -->|is a| n_parallelism
classDef center stroke-width:3px
class n_task_parallelism center
classDef outside stroke-dasharray: 4 3
class n_data_parallelism,n_fork_join,n_parallelism outside
- Is a kind of: Parallelism
- Kinds: Fork-join
- Often confused with: Data parallelism
In each language¶
| Rust | Rayon's join ↗ runs two closures, potentially in parallel |
| Go | go statements, with a sync.WaitGroup ↗ to wait for them |
| C++ | std::async ↗ with std::launch::async |
| Java | ForkJoinTask ↗ fork and join; StructuredTaskScope ↗ is still a preview API in JDK 25 |
| Python | Executor.submit ↗ |
| C# | Parallel.Invoke ↗ and task parallelism ↗ |
| Swift | async let and task groups ↗ |
Where to read more¶
- In the books: Concurrent Programming on Windows, Joe Duffy — ch. 13, 'Data and Task Parallelism'
- In the books: Pro Asynchronous Programming with .NET, Richard Blewett, Andrew Clymer — ch. 10, 'TPL Dataflow'
- In the books: Pro TBB, Michael Voss, Rafael Asenjo, James Reinders — ch. 2, 'Generic Parallel Algorithms' → 'Functional / Task Parallelism'
- In the books: Programming Concurrency on the JVM, Venkat Subramaniam — ch. 4, 'Scalability and Thread Safety' → 'Java 7 Fork-Join API'
- In the books: Parallel Programming and Concurrency with C# 10 and .NET 6, Alvin Ashcraft — ch. 6, 'Parallel Programming Concepts' → 'Getting started with the TPL'
- In the books: Concurrency in .NET, Riccardo Terrell — ch. 7, 'Task-based functional parallelism' → 'The .NET Task Parallel Library'
- Reference: Wikipedia: Task parallelism ↗