cppthread 1.1.16
C++ Thread Library
Public Types | Public Member Functions | Private Attributes | List of all members
cppthread::pool< W, A >::worker_thread_t Class Reference

Class used to manage the worker and worker thread. More...

Public Types

typedef std::shared_ptr< worker_thread_tpointer_t
 The shared pointer type to a worker thread.
 
typedef std::vector< pointer_tvector_t
 The vector of shared pointers.
 

Public Member Functions

 worker_thread_t (std::string const &name, std::size_t i, typename worker_fifo_t::pointer_t in, typename worker_fifo_t::pointer_t out, A... args)
 The constructor of a worker thread.
 
W & get_worker ()
 Retrieve a pointer to the working in this worker thread.
 
W const & get_worker () const
 Retrieve the worker when the worker thread is constant.
 

Private Attributes

thread::pointer_t f_thread
 The thread which manages the worker.
 
f_worker
 The worker, which is a runner.
 

Detailed Description

template<class W, class ... A>
class cppthread::pool< W, A >::worker_thread_t

This class creates a worker thread, it adds it to a thread, and it starts the thread. It is here so we have a single list of worker threads.

Note
I had to allocate a cppthread object because at this point the cppthread is not yet fully defined so it would not take it otherwise. It certainly would be possible to move this declaration and those depending on it to avoid this problem, though.

Definition at line 55 of file pool.h.

Member Typedef Documentation

◆ pointer_t

template<class W , class ... A>
cppthread::pool< W, A >::worker_thread_t::pointer_t

When the pool creates worker threads, it allocates them as shared pointers and saves them in a vector.

See also
pool::worker_thread_t::vector_t

Definition at line 58 of file pool.h.

◆ vector_t

template<class W , class ... A>
cppthread::pool< W, A >::worker_thread_t::vector_t

When you create a pool of worker threads, it creates a set of threads that it saves in a vector of this type. The pointers to the threads are shared pointers.

Definition at line 59 of file pool.h.

Constructor & Destructor Documentation

◆ worker_thread_t()

template<class W , class ... A>
cppthread::pool< W, A >::worker_thread_t::worker_thread_t ( std::string const &  name,
std::size_t  i,
typename worker_fifo_t::pointer_t  in,
typename worker_fifo_t::pointer_t  out,
A...  args 
)
inline

A worker thread is a thread and a runner manager.

The name is used by the thread. For the worker, we append " (worker #...)" to the name and assign that to the worker. This way, we can distinguish each worker properly.

The i parameter is the index representing the worker number. It has no special anything otherwise.

The input fifo (in) must be defined on construction. It gets passed to all the workers so they all can wait for new workload messages.

The output fifo (out) is optional. If you use the item_with_predicate with actual predicates, remember that a workload needs to be released for the predicate to become true. Adding them to another fifo may prevent this pool from processing additional workloads for long periods of time.

Parameters
[in]nameThe name of the thread and worker.
[in]iThe index of this worker thread.
[in]inThe input fifo where workloads are sent.
[in]outThe output fifo where workloads are forwarded once worked on. This parameter is optional (you can use a nullptr.
[in]argsAdditional arguments to construct the worker threads runners (as per your type W).

Definition at line 61 of file pool.h.

References cppthread::pool< W, A >::worker_thread_t::f_thread, and cppthread::to_string().

Here is the call graph for this function:

Member Function Documentation

◆ get_worker() [1/2]

template<class W , class ... A>
cppthread::pool< W, A >::worker_thread_t::get_worker ( )
inline

This function is used to access the worker of the worker_thread_t object.

Returns
A pointer to the worker thread.

Definition at line 76 of file pool.h.

References cppthread::pool< W, A >::worker_thread_t::f_worker.

◆ get_worker() [2/2]

template<class W , class ... A>
cppthread::pool< W, A >::worker_thread_t::get_worker ( ) const
inline

This function is used to access the worker of the worker_thread_t object.

Returns
A pointer to the worker thread.

Definition at line 81 of file pool.h.

References cppthread::pool< W, A >::worker_thread_t::f_worker.

Member Data Documentation

◆ f_thread

template<class W , class ... A>
cppthread::pool< W, A >::worker_thread_t::f_thread
private

This object is a thread used to manage the corresponding worker thread which is the operating system thread.

Definition at line 88 of file pool.h.

Referenced by cppthread::pool< W, A >::worker_thread_t::worker_thread_t().

◆ f_worker

template<class W , class ... A>
cppthread::pool< W, A >::worker_thread_t::f_worker
private

The work is a runner of the type you decide through W. It gets initialized and started when you create the pool. It immediately listens on the input fifo which can already have workload items as required.

Definition at line 87 of file pool.h.

Referenced by cppthread::pool< W, A >::worker_thread_t::get_worker(), and cppthread::pool< W, A >::worker_thread_t::get_worker().


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

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.