Electroneum
Classes | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
tools::thread_group Class Reference

Manages zero or more threads for work dispatching. More...

#include <thread_group.h>

Classes

class  data
 

Public Member Functions

 thread_group ()
 Create an optimal number of threads. More...
 
 thread_group (std::size_t count)
 Create exactly count threads. More...
 
 thread_group (thread_group const &)=delete
 
 thread_group (thread_group &&)=delete
 
 ~thread_group ()=default
 Joins threads, but does not necessarily run all dispatched functions. More...
 
thread_groupoperator= (thread_group const &)=delete
 
thread_groupoperator= (thread_group &&)=delete
 
std::size_t count () const noexcept
 
bool try_run_one () noexcept
 
template<typename F >
void dispatch (F &&f)
 

Static Public Member Functions

static std::size_t optimal ()
 
static std::size_t optimal_with_max (std::size_t count)
 

Private Attributes

boost::optional< datainternal
 

Detailed Description

Manages zero or more threads for work dispatching.

Constructor & Destructor Documentation

◆ thread_group() [1/4]

tools::thread_group::thread_group ( )
inlineexplicit

Create an optimal number of threads.

◆ thread_group() [2/4]

tools::thread_group::thread_group ( std::size_t  count)
explicit

Create exactly count threads.

◆ thread_group() [3/4]

tools::thread_group::thread_group ( thread_group const &  )
delete

◆ thread_group() [4/4]

tools::thread_group::thread_group ( thread_group &&  )
delete

◆ ~thread_group()

tools::thread_group::~thread_group ( )
default

Joins threads, but does not necessarily run all dispatched functions.

Member Function Documentation

◆ count()

std::size_t tools::thread_group::count ( ) const
inlinenoexcept
Returns
Number of threads owned by this group.

◆ dispatch()

template<typename F >
void tools::thread_group::dispatch ( F &&  f)
inline

f is invoked immediately if count() == 0, otherwise execution of f is queued for next available thread. If f is queued, any exception leaving that function will result in process termination. Use std::packaged_task if exceptions need to be handled.

◆ operator=() [1/2]

thread_group& tools::thread_group::operator= ( thread_group const &  )
delete

◆ operator=() [2/2]

thread_group& tools::thread_group::operator= ( thread_group &&  )
delete

◆ optimal()

std::size_t tools::thread_group::optimal ( )
static

◆ optimal_with_max()

std::size_t tools::thread_group::optimal_with_max ( std::size_t  count)
static
Returns
count ? min(count - 1, optimal()) : 0

◆ try_run_one()

bool tools::thread_group::try_run_one ( )
inlinenoexcept
Returns
True iff a function was available and executed (on this_thread).

Member Data Documentation

◆ internal

boost::optional<data> tools::thread_group::internal
private

The documentation for this class was generated from the following files: