|
Orrery
A GPU-accelerated N-body gravitational simulator
|
Worker threads and a way to run something on all of them at once. More...
#include <orrery/backend/thread_pool.hpp>
Public Types | |
| enum class | Affinity : std::uint8_t { kUnpinned , kPinned } |
| Whether workers are tied to a particular logical processor. More... | |
| using | WorkerBody = core::FunctionRef<void(unsigned)> |
| What each worker is asked to do, given its own index. | |
Public Member Functions | |
| ThreadPool (unsigned worker_count=0, Affinity affinity=Affinity::kUnpinned) | |
| Start worker_count threads, or one per logical processor if zero. | |
| ~ThreadPool () | |
| Stop the workers and join them. | |
| ThreadPool (const ThreadPool &)=delete | |
| ThreadPool & | operator= (const ThreadPool &)=delete |
| ThreadPool (ThreadPool &&)=delete | |
| ThreadPool & | operator= (ThreadPool &&)=delete |
| void | dispatch (WorkerBody body) |
| Run body(worker) once on every worker and return when all have returned. | |
| unsigned | worker_count () const noexcept |
| Affinity | affinity () const noexcept |
| CoreClass | core_class (unsigned worker) const noexcept |
| The class of core worker runs on, or kUnknown when unpinned or undiscoverable. | |
Static Public Member Functions | |
| static unsigned | default_worker_count () noexcept |
| One worker per logical processor, and never zero. | |
Worker threads and a way to run something on all of them at once.
|
strong |
Whether workers are tied to a particular logical processor.
|
explicit |
Start worker_count threads, or one per logical processor if zero.
The constructor returns only once every worker has started and, when pinned, settled on its processor. Waiting costs a few hundred microseconds once, and it means the first region measured is not also measuring thread creation.
| void orrery::backend::ThreadPool::dispatch | ( | WorkerBody | body | ) |
Run body(worker) once on every worker and return when all have returned.
Call from one thread at a time. The pool is a tool a solver uses to parallelise its own loop, not a general task queue serving many submitters, and one submitter is what every caller in this project is.
body must not throw, for the reason executor.hpp gives.
|
staticnodiscardnoexcept |
One worker per logical processor, and never zero.
hardware_concurrency is permitted to return zero when it cannot tell, and a pool of no threads would never run anything.