libDwm-0.6.0
Dwm::LoadBalancer< ItemT > Class Template Reference

A simple load balancer class template which balances work across Worker objects that each run in their own thread. More...

#include <DwmLoadBalancer.hh>

Classes

class  CompareWorkers
 Comparison class for workers within the LoadBalancer. More...
 
class  Worker
 Worker class for LoadBalancer. More...
 

Public Member Functions

void AddWorker (Worker *worker)
 Adds the given worker to the load balancer.
 
void AddWork (ItemT item)
 Adds work to be done with load balancing.
 
template<typename InputIterator >
void AddWork (InputIterator firstIter, InputIterator lastIter)
 Adds work to be done with load balancing.
 
void Stop ()
 Calls Worker::Stop() on all encapsulated Worker objects.
 
const std::vector< Worker * > & Workers () const
 Returns a const reference to the encapsulated workers.
 

Detailed Description

template<typename ItemT>
class Dwm::LoadBalancer< ItemT >

A simple load balancer class template which balances work across Worker objects that each run in their own thread.

A user would derive a worker class from LoadBalancer<ItemT>::Worker, and implement the Worker::ProcessWork(ItemT) member. The worker can be added to a LoadBalancer via the LoadBalancer::AddWorker() member. Work can be added to the LoadBalancer with AddWork(ItemT). A unit of work is encapsulated in the ItemT template parameter. This is a template so that any copyable type can be used as a unit of work.

Today, this class template may not be all that useful (we have the concurrency features of C++11 and C++14). I originally wrote this class using pthreads, before we had C++11 and C++14. It's still in use in some of my code, but I may revisit this soon and modernize it. For now the only modernization is the migration to std::thread.


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