SObjectizer  5.5
Namespaces | Classes | Typedefs | Enumerations | Functions
so_5::disp::thread_pool Namespace Reference

Thread pool dispatcher. More...

Namespaces

 anonymous_namespace{pub.cpp}
 
 common_implementation
 Reusable implementation of some thread pool dispatcher functionality which can be used in other thread-pool-like dispatchers.
 
 impl
 Internal implementation details of thread pool dispatcher.
 

Classes

class  bind_params_t
 Parameters for binding agents to thread_pool dispatcher. More...
 
class  disp_params_t
 Alias for namespace with traits of event queue. More...
 
class  private_dispatcher_t
 An interface for thread_pool private dispatcher. More...
 

Typedefs

using params_t = bind_params_t
 Alias for bind_params. More...
 
using private_dispatcher_handle_t = so_5::intrusive_ptr_t< private_dispatcher_t >
 A handle for the thread_pool private dispatcher. More...
 

Enumerations

enum  fifo_t { fifo_t::cooperation, fifo_t::individual }
 Type of FIFO mechanism for agent's demands. More...
 

Functions

SO_5_FUNC dispatcher_unique_ptr_t create_disp ( disp_params_t params)
 Create thread pool dispatcher. More...
 
SO_5_FUNC private_dispatcher_handle_t create_private_disp ( environment_t &env, disp_params_t disp_params, const std::string &data_sources_name_base)
 Create a private thread_pool dispatcher. More...
 
SO_5_FUNC disp_binder_unique_ptr_t create_disp_binder ( std::string disp_name, const bind_params_t &params)
 Create dispatcher binder for thread pool dispatcher. More...
 
std::size_t default_thread_pool_size ()
 A helper function for detecting default thread count for thread pool. More...
 
dispatcher_unique_ptr_t create_disp (std::size_t thread_count)
 Create thread pool dispatcher. More...
 
dispatcher_unique_ptr_t create_disp ()
 Create thread pool dispatcher. More...
 
private_dispatcher_handle_t create_private_disp (environment_t &env, const std::string &data_sources_name_base, disp_params_t disp_params)
 Create a private thread_pool dispatcher. More...
 
private_dispatcher_handle_t create_private_disp (environment_t &env, std::size_t thread_count, const std::string &data_sources_name_base)
 Create a private thread_pool dispatcher. More...
 
private_dispatcher_handle_t create_private_disp (environment_t &env, std::size_t thread_count)
 Create a private thread_pool dispatcher. More...
 
private_dispatcher_handle_t create_private_disp (environment_t &env)
 Create a private thread_pool dispatcher with the default count of working threads. More...
 
template<typename Setter >
disp_binder_unique_ptr_t create_disp_binder (std::string disp_name, Setter params_setter)
 Create dispatcher binder for thread pool dispatcher. More...
 

Detailed Description

Thread pool dispatcher.

Typedef Documentation

◆ params_t

Alias for bind_params.

Deprecated:
Since v.5.5.11 bind_params_t must be used instead.
Since
v.5.4.0

◆ private_dispatcher_handle_t

A handle for the thread_pool private dispatcher.

Since
v.5.5.4

Enumeration Type Documentation

◆ fifo_t

Type of FIFO mechanism for agent's demands.

Since
v.5.4.0
Enumerator
cooperation 

A FIFO for demands for all agents from the same cooperation.

It means that agents from the same cooperation for which this FIFO mechanism is used will be worked on the same thread.

individual 

A FIFO for demands only for one agent.

It means that FIFO is only supported for the concrete agent. If several agents from a cooperation have this FIFO type they will process demands independently and on different threads.

Function Documentation

◆ create_disp() [1/3]

SO_5_FUNC dispatcher_unique_ptr_t so_5::disp::thread_pool::create_disp ( disp_params_t  params)

Create thread pool dispatcher.

Usage sample
so_5::launch( []( so_5::environment_t & env ) {...},
[]( so_5::environment_params_t & env_params ) {
using namespace so_5::disp::thread_pool;
env_params.add_named_dispatcher( create_disp(
.thread_count( 16 )
} ) );
} );
Since
v.5.5.11
Parameters
paramsParameters for the dispatcher.
Examples:
so_5/hardwork_imit/main.cpp.

◆ create_disp() [2/3]

dispatcher_unique_ptr_t so_5::disp::thread_pool::create_disp ( std::size_t  thread_count)
inline

Create thread pool dispatcher.

Since
v.5.4.0
Parameters
thread_countCount of working threads.

◆ create_disp() [3/3]

dispatcher_unique_ptr_t so_5::disp::thread_pool::create_disp ( )
inline

Create thread pool dispatcher.

Size of pool is detected automatically.

Since
v.5.4.0

◆ create_disp_binder() [1/2]

SO_5_FUNC disp_binder_unique_ptr_t so_5::disp::thread_pool::create_disp_binder ( std::string  disp_name,
const bind_params_t params 
)

Create dispatcher binder for thread pool dispatcher.

Since
v.5.4.0
Parameters
disp_nameName of the dispatcher.
paramsParameters for binding.
Examples:
so_5/hardwork_imit/main.cpp.

◆ create_disp_binder() [2/2]

template<typename Setter >
disp_binder_unique_ptr_t so_5::disp::thread_pool::create_disp_binder ( std::string  disp_name,
Setter  params_setter 
)
inline

Create dispatcher binder for thread pool dispatcher.

Usage example:

Since
v.5.4.0
Parameters
disp_nameName of the dispatcher.
params_setterFunction for setting the binding's params.

◆ create_private_disp() [1/5]

SO_5_FUNC private_dispatcher_handle_t so_5::disp::thread_pool::create_private_disp ( environment_t env,
disp_params_t  disp_params,
const std::string &  data_sources_name_base 
)

Create a private thread_pool dispatcher.

Usage sample
using namespace so_5::disp::thread_pool;
auto private_disp = create_private_disp(
env,
.thread_count( 16 )
} ),
"db_workers_pool" );
auto coop = env.create_coop( so_5::autoname,
// The main dispatcher for that coop will be
// private thread_pool dispatcher.
private_disp->binder( bind_params_t{} ) );
Since
v.5.5.11
Parameters
envSObjectizer Environment to work in.
disp_paramsParameters for the dispatcher.
data_sources_name_baseValue for creating names of data sources for run-time monitoring.
Examples:
so_5/collector_many_performers/main.cpp, so_5/collector_performer_pair/main.cpp, so_5/queue_size_stats/main.cpp, so_5/redirect_and_transform/main.cpp, so_5/simple_message_deadline/main.cpp, and so_5/work_generation/main.cpp.

◆ create_private_disp() [2/5]

private_dispatcher_handle_t so_5::disp::thread_pool::create_private_disp ( environment_t env,
const std::string &  data_sources_name_base,
disp_params_t  disp_params 
)
inline

Create a private thread_pool dispatcher.

Since
v.5.5.15.1
Usage sample
using namespace so_5::disp::thread_pool;
auto private_disp = create_private_disp(
env,
"db_workers_pool",
.thread_count( 16 )
} ) );
auto coop = env.create_coop( so_5::autoname,
// The main dispatcher for that coop will be
// private thread_pool dispatcher.
private_disp->binder( bind_params_t{} ) );

This function is added to fix order of parameters and make it similar to create_private_disp from other dispatchers.

Parameters
envSObjectizer Environment to work in.
data_sources_name_baseValue for creating names of data sources for run-time monitoring.
disp_paramsParameters for the dispatcher.

◆ create_private_disp() [3/5]

private_dispatcher_handle_t so_5::disp::thread_pool::create_private_disp ( environment_t env,
std::size_t  thread_count,
const std::string &  data_sources_name_base 
)
inline

Create a private thread_pool dispatcher.

Usage sample
env,
16,
"db_workers_pool" );
auto coop = env.create_coop( so_5::autoname,
// The main dispatcher for that coop will be
// private thread_pool dispatcher.
private_disp->binder( so_5::disp::thread_pool::bind_params_t{} ) );
Since
v.5.5.4
Parameters
envSObjectizer Environment to work in.
thread_countCount of working threads.
data_sources_name_baseValue for creating names of data sources for run-time monitoring.

◆ create_private_disp() [4/5]

private_dispatcher_handle_t so_5::disp::thread_pool::create_private_disp ( environment_t env,
std::size_t  thread_count 
)
inline

Create a private thread_pool dispatcher.

Usage sample
auto private_disp = so_5::disp::thread_pool::create_private_disp( env, 16 );
auto coop = env.create_coop( so_5::autoname,
// The main dispatcher for that coop will be
// private thread_pool dispatcher.
private_disp->binder( so_5::disp::thread_pool::bind_params_t{} ) );
Since
v.5.5.4
Parameters
envSObjectizer Environment to work in.
thread_countCount of working threads.

◆ create_private_disp() [5/5]

private_dispatcher_handle_t so_5::disp::thread_pool::create_private_disp ( environment_t env)
inline

Create a private thread_pool dispatcher with the default count of working threads.

Usage sample
auto coop = env.create_coop( so_5::autoname,
// The main dispatcher for that coop will be
// private thread_pool dispatcher.
private_disp->binder( so_5::disp::thread_pool::bind_params_t{} ) );
Since
v.5.5.4
Parameters
envSObjectizer Environment to work in.

◆ default_thread_pool_size()

std::size_t so_5::disp::thread_pool::default_thread_pool_size ( )
inline

A helper function for detecting default thread count for thread pool.

Since
v.5.4.0