|
NumericAL
A header-only C++20 lexer built on REAL
|
The threads every kernel shares, started once: a parallel_for costs a wake-up, not a thread start. More...
#include <parallel.hpp>
Public Member Functions | |
| thread_pool (const thread_pool &)=delete | |
| thread_pool & | operator= (const thread_pool &)=delete |
| thread_pool (thread_pool &&)=delete | |
| thread_pool & | operator= (thread_pool &&)=delete |
| ~thread_pool ()=delete | |
| bool | try_run (chunk_runner run, const void *body, std::size_t count, std::size_t chunk, std::size_t chunks, std::size_t helpers, side_runner side=nullptr, const void *side_body=nullptr) |
Runs chunks chunks of chunk indices up to count on the caller and at most helpers workers, then rethrows the first exception in index order. | |
Static Public Member Functions | |
| static thread_pool & | shared () |
| The pool, started on first use with a worker per hardware thread beside the caller. | |
Private Member Functions | |
| thread_pool ()=default | |
| void | start () |
Starts the workers (after construction: each uses the pool), worker_cores: on Linux one per core, pinned there. Free to move, as a caller is, two threads at times shared one core's hyperthreads (a product of order 1024 on eight AVX2 cores took 8.1 ms, or 10.4 in most processes). | |
| void | serve (worker_bell &bell) |
A worker on core: waits for a run (polling a while, then asleep), works on it unless it sits it out, waits for the next. | |
Private Attributes | |
| std::mutex | lock_ |
| Guards current_ and generation_. | |
| std::vector< std::unique_ptr< worker_bell > > | bells_ |
| Each worker's, set before it starts. | |
| std::shared_ptr< pool_job > | current_ |
| The latest run. | |
| std::atomic< std::size_t > | generation_ {0} |
| Counts the runs (polled without the lock). | |
| std::atomic< bool > | busy_ {false} |
| Whether a run holds the pool. | |
| std::size_t | workers_ {0} |
| The threads started. | |
| long | owner_ {current_process()} |
| The process whose threads they are. | |
The threads every kernel shares, started once: a parallel_for costs a wake-up, not a thread start.
The caller takes chunks beside the workers, each taking the next chunk as it frees up (a slower core takes fewer). One run at a time: a parallel_for while the pool is busy (another thread's, or one nested in a body) runs its chunks itself, with the same result. The pool is never destroyed: its threads wait for work until the process ends, so no static destructor races them.
Definition at line 313 of file parallel.hpp.
|
delete |
|
delete |
|
delete |
|
privatedefault |
|
delete |
|
delete |
|
inlineprivate |
A worker on core: waits for a run (polling a while, then asleep), works on it unless it sits it out, waits for the next.
Definition at line 464 of file parallel.hpp.
|
inlinestatic |
The pool, started on first use with a worker per hardware thread beside the caller.
| std::system_error | If the system starts no thread (the workers already started keep the pool, which a later call starts again). |
Definition at line 328 of file parallel.hpp.
|
inlineprivate |
Starts the workers (after construction: each uses the pool), worker_cores: on Linux one per core, pinned there. Free to move, as a caller is, two threads at times shared one core's hyperthreads (a product of order 1024 on eight AVX2 cores took 8.1 ms, or 10.4 in most processes).
Definition at line 438 of file parallel.hpp.
|
inline |
Runs chunks chunks of chunk indices up to count on the caller and at most helpers workers, then rethrows the first exception in index order.
side, the caller runs it first, while the workers take chunks, and its exception comes back before theirs. Definition at line 344 of file parallel.hpp.
|
private |
Each worker's, set before it starts.
Definition at line 513 of file parallel.hpp.
Whether a run holds the pool.
Definition at line 516 of file parallel.hpp.
|
private |
The latest run.
Definition at line 514 of file parallel.hpp.
|
private |
Counts the runs (polled without the lock).
Definition at line 515 of file parallel.hpp.
|
private |
Guards current_ and generation_.
Definition at line 512 of file parallel.hpp.
|
private |
The process whose threads they are.
Definition at line 521 of file parallel.hpp.
|
private |
The threads started.
Definition at line 517 of file parallel.hpp.