asynchrony 0.0.0
Add asynchrony to your C++ applications using standard C++20
Loading...
Searching...
No Matches
siddiqsoft::simple_pool< T, N > Struct Template Reference

Implements a single deque based vector of jthreads. All threads wait on the next available item via semaphore and invoke the callback on the next item from the deque. Items in the deque are lock-accessed. More...

#include </opt/azure-agent/_work/14/s/include/siddiqsoft/simple_pool.hpp>

Public Member Functions

 simple_pool (simple_pool &&)=delete
simple_pool & operator= (simple_pool &&)=delete
 simple_pool (simple_pool &)=delete
simple_pool & operator= (simple_pool &)=delete
 ~simple_pool ()
 Destructor.
 simple_pool (std::function< void(T &&)> c)
 Contructs a threadpool with N threads with the given callback/worker function.
void queue (T &&item)
 Queue item into the deque (takes "ownership" of the item).

Static Public Attributes

static constexpr std::chrono::milliseconds DEFAULT_WAIT_FOR_NEXT_ITEM_MS {1500}

Detailed Description

template<typename T, uint16_t N = 0>
requires std::is_move_constructible_v<T>
struct siddiqsoft::simple_pool< T, N >

Implements a single deque based vector of jthreads. All threads wait on the next available item via semaphore and invoke the callback on the next item from the deque. Items in the deque are lock-accessed.

Template Parameters
TYour datatype #tparam N Number of threads in the pool. Leave it to 0 to use the value returned by std::thread::hardware_concurrency()
Remarks
The number of threads in the pool is determined by the nature of your "work". If you're spending time against db then you might wish to use more threads as individual queries might take time and hog the thread.

Definition at line 59 of file simple_pool.hpp.

Constructor & Destructor Documentation

◆ ~simple_pool()

template<typename T, uint16_t N = 0>
siddiqsoft::simple_pool< T, N >::~simple_pool ( )
inline

Destructor.

Remarks
We need to make sure that the signal wait interval is reduced to 0ms to allow our threads (which are waiting on the signal) to be stopped.

Definition at line 72 of file simple_pool.hpp.

◆ simple_pool()

template<typename T, uint16_t N = 0>
siddiqsoft::simple_pool< T, N >::simple_pool ( std::function< void(T &&)> c)
inline

Contructs a threadpool with N threads with the given callback/worker function.

Parameters
cThe worker function.

Definition at line 86 of file simple_pool.hpp.

Member Function Documentation

◆ queue()

template<typename T, uint16_t N = 0>
void siddiqsoft::simple_pool< T, N >::queue ( T && item)
inline

Queue item into the deque (takes "ownership" of the item).

Parameters
itemItem to queue must be move'd

Definition at line 121 of file simple_pool.hpp.

Member Data Documentation

◆ DEFAULT_WAIT_FOR_NEXT_ITEM_MS

template<typename T, uint16_t N = 0>
std::chrono::milliseconds siddiqsoft::simple_pool< T, N >::DEFAULT_WAIT_FOR_NEXT_ITEM_MS {1500}
staticconstexpr

Definition at line 61 of file simple_pool.hpp.


The documentation for this struct was generated from the following file: