Thread pool and executor¶
Category: Units of execution · Status: stub · Lessons: chapter 01, Threads
One line: A set of threads that run submitted tasks one after another, so the cost of starting a thread is paid once rather than once per task.
Also called: executor, ExecutorService, ThreadPoolExecutor.
How it connects¶
flowchart LR
n_openmp["OpenMP"]
n_parallel_iterators["Parallel iterators and streams"]
n_thread["Thread"]
n_thread_pool["Thread pool and executor"]
n_openmp -->|uses| n_thread_pool
n_parallel_iterators -->|uses| n_thread_pool
n_thread_pool -->|uses| n_thread
classDef center stroke-width:3px
class n_thread_pool center
classDef outside stroke-dasharray: 4 3
class n_openmp,n_parallel_iterators,n_thread outside
- Is built on: Thread
- Is used by: OpenMP, Parallel iterators and streams
- See also: Concurrency primitives, Oversubscription, Work stealing, Worker pool
In each language¶
| Rust | None in the standard library; the Rayon crate has ThreadPool ↗ |
| Go | No pool type: a fixed number of goroutines receiving from one channel, as in bounded parallelism ↗ |
| Java | ExecutorService ↗, from the Executors ↗ factories or ThreadPoolExecutor ↗ |
| Python | ThreadPoolExecutor ↗ and ProcessPoolExecutor |
| C# | The managed thread pool ↗: one per process, used by Task |
| Kotlin | Dispatchers.Default ↗ and Dispatchers.IO are shared pools of threads |
| Swift | Dispatch ↗ queues, run on threads the system manages |
Where to read more¶
- In this library: Getting a result back
- In a sibling library: Go: A worker pool ↗
- In the books: Hands-On Concurrency with Rust, Brian L. Troutwine — ch. 8, 'High-Level Parallelism – Threadpools, Parallel Iterators and Processes'
- In the books: Java Concurrency in Practice, Brian Goetz, Tim Peierls, Joshua Bloch, Joseph Bowbeer, David Holmes, Doug Lea — ch. 8, 'Applying Thread Pools'
- In the books: Concurrent Programming on Windows, Joe Duffy — ch. 7, 'Thread Pools'
- In the books: Parallel Loops in Python, Jason Brownlee — ch. 3, 'Parallel Loop with the ThreadPool Class'
- In the books: Pthreads Programming, Bradford Nichols, Dick Buttlar, Jacqueline Proulx Farrell — ch. 3, 'Synchronizing Pthreads' → 'Thread Pools'
- In the books: C++ Concurrency in Action, Anthony Williams — ch. 9, 'Advanced thread management' → 'Thread pools'
- In the books: Fluent Python, Luciano Ramalho — ch. 20, 'Concurrent Executors'
- In the books: Effective Java, Joshua Bloch — ch. 11, 'Concurrency' → 'Item 80: Prefer executors, tasks, and streams to threads'
- In the books: Learning Concurrent Programming in Scala, Aleksandar Prokopec — ch. 3, 'Traditional Building Blocks of Concurrency' → 'The Executor and ExecutionContext objects'
- Reference: Wikipedia: Thread pool ↗