Class static_thread_pool¶
Defined in File thread_pool.hpp
Class Documentation¶
-
class
concore::v1::static_thread_pool¶ A pool of threads that can execute work.
This is constructed with the number of threads that are needed in the pool. Once constructed, these threads cannot be detached from the pool. The user is allowed to attach other threads to the pool, but without any possibility of detaching them earlier than the destruction of the pool. There is no automatic resizing of the pool.
The user can manually signal the thread pool to stop processing items, and/or wait for the existing work items to drain out.
When destructing this object, the implementation ensures to wait on all the in-progress items.
Any scheduler or executor objects that are created cannot exceed the lifetime of this object.
Properties of the static_thread_pool executor:
blocking.always
relationship.fork
outstanding_work.untracked
bulk_guarantee.parallel
mapping.thread
Public Types
-
using
scheduler_type= detail::thread_pool_scheduler¶ The type of scheduler that this object exposes.
-
using
executor_type= detail::thread_pool_executor¶ The type of executor that this object exposes.
Public Functions
-
static_thread_pool(std::size_t num_threads)¶ Constructs a thread pool.
This thread pool will create the given number of “internal” threads. This number of threads cannot be changed later on. In addition to these threads, the user might manually add other threads in the pool by calling the
attach() method.- Parameters
num_threads: The number of threads to statically create in the thread pool
- See
-
static_thread_pool(const static_thread_pool&) = delete¶ Copy constructor is DISABLED.
-
static_thread_pool &
operator=(const static_thread_pool&) = delete¶ Copy assignment is DISABLED.
-
static_thread_pool(static_thread_pool&&) = default¶ Move constructor.
-
static_thread_pool &
operator=(static_thread_pool&&) = default¶ Move assignment.
-
~static_thread_pool()¶ Destructor for the static pool.
Ensures that all the tasks already in the pool are drained out before destructing the pool. New tasks will not be executed anymore in the pool.
-
void
attach()¶ Attach the current thread to the thread pool.
The thread that is calling this will temporary join this thread pool. The thread will behave as if it was created during the constructor of this class. The thread will be released from the pool (and return to the caller) whenever the stop() and wait() are releasing the threads from this pool.
If the thread pool is stopped, this will exit immediately without attaching the current thread to the thread pool.
-
void
stop()¶ Signal all work to complete.
This will signal the thread pool to stop working as soon as possible. This will return immediately without waiting on the worker threads to complete.
After calling this, no new work will be taken by the thread pool.
This will cause the threads attached to this pool to detach (after completing ongoing work).
This is not thread-safe. Ensure that this is called from a single thread.
-
void
wait()¶ Wait for all the threads attached to the thread pool to complete.
If not already stopped, it will signal the thread pool for completion. Calling just wait() is similar to calling stop() and then wait().
If there are ongoing tasks in the pool that are still executing, this will block until all these tasks are completed.
After the call to this function, all threads are either terminated or detached from the thread pool.
-
scheduler_type
scheduler() noexcept¶ Returns a scheduler that can be used to schedule work here.
The returned scheduler object can be used to create sender objects that may be used to submit receiver objects to this thread pool.
The returned object has the following properties:
execution::allocator
execution::allocator(std::allocator<void>())
- See
-
executor_type
executor() noexcept¶ Returns an executor object that can add work to this thread pool.
This returns an executor object that can be used to submit function objects to be executed by this thread pool.
The returned object has the following properties:
execution::blocking.possibly
execution::relationship.fork
execution::outstanding_work.untracked
execution::allocator
execution::allocator(std::allocator<void>())
- See