Thread Pool Elements
summary
Prototype thread pool implemented in C++20 inside Compiler Explorer uses a std::deque work queue, condition_variable, std::stop_source/stop_token and an atomic working counter, growing threads up to hardware_concurrency (which is two on Compiler Explorer). A real bug appears: capturing this in lambdas plus a resizing std::vector of thread contexts lets moved threads keep dangling pointers; reserving avoids it but doesn’t solve dynamic shrink/move. Sanitizers (thread sanitizer and memory sanitizer) catch the corruption; QThreadPool remains preferred for production.
AI-written summary · about
chapters (16)
- 0:00Introduction
- 2:01Producer-consumer overview
- 3:01Simple thread-safe container
- 4:32Notification mechanisms
- 7:12Use cases and design
- 10:18Thread pool elements
- 13:09QThreadPool approach
- 14:51Execution context types
- 17:28Scaling and locking
- 18:07Mutex and sync details
- 20:48Mutex strategies
- 24:53Stop tokens and callbacks
- 31:44Memory and error handling
- 42:41Modern C++ execution
- 45:06Coroutines and conclusions
- 48:07Testing and future steps
related talks
01h 07mAn Introduction to Multithreading in C++20
59mThreads and Locks must Go
01h 04m[old version]The C++20 Synchrononization Library
01h 04mThe C++20 Synchronization Library
52mBest Practices for Concurrency
48mReal time 101
01h 04mConcurrency TS2: Improved C++ Concurrency and Lock-free Programming
01h 03m...Scaling Visualization in concurrent C++ programs
