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

Implements a lock-free round robin work allocation into vector of simple_worker<T>. More...

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

Public Member Functions

 roundrobin_pool (roundrobin_pool &&)=delete
auto operator= (roundrobin_pool &&)=delete
 roundrobin_pool (roundrobin_pool &)=delete
auto operator= (roundrobin_pool &)=delete
 roundrobin_pool (std::function< void(T &&)> c)
 Consturcts a deque of simple_worker<T> with the given callback.
void queue (T &&item)
 Queue item into one of the thread's queue.

Detailed Description

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

Implements a lock-free round robin work allocation into vector of simple_worker<T>.

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 53 of file roundrobin_pool.hpp.

Constructor & Destructor Documentation

◆ roundrobin_pool()

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

Consturcts a deque of simple_worker<T> with the given callback.

Parameters
cCallback worker function

Definition at line 64 of file roundrobin_pool.hpp.

Member Function Documentation

◆ queue()

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

Queue item into one of the thread's queue.

Parameters
itemThe item must be std::move'd
Remarks
The choice of the roundrobin might mean that if one thread is blocked then the rest of the items for this queue would be blocked. The cost of the % is cheaper than the cost it takes to pay for locks. The round-robin approach ensures that the underlying deque isn't being pop'd and push'd by multiple threads as there is only one consumer for that deque (one per thread) while we may have any number of producers.

Definition at line 82 of file roundrobin_pool.hpp.


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