library of assembled shared sources

http://lass.cocamware.com

ThreadPool Class Reference
[Threading]

Production-Consumer concurrency pattern. More...

#include <thread_pool.h>


Detailed Description

Production-Consumer concurrency pattern.

Author:
Bramz
  #include <lass/util/thread_pool.h>
  #include <lass/util/bind.h>
  using namespace lass::util;

  void parallelWork(int begin, int end);
  const int n = 1000000;
  const int step = 1000;

  util::ThreadPool<> pool;
  for (int i = 0; i < n; i += step)
  {
    pool.addTask(bind(parallelWork, i, std::min(i + step, n)));
  }
  pool.completeAllTasks();

Good-Practice

Using the policies and constructor parameters, the ThreadPool can be operated in many different configurations. However, there are two that are particular interesting:

Best used when short bursts of a bounded number of tasks are followed by completeAllTasks(). Example: A single task is splitted in a parallel subtasks, all feeded to the pool at once, and completeAllTasks() is called to finish the grand tasks.

Best used when a continues (unbounded) stream of tasks reaches a server.

Policies

IdlePolicy

  class IdlePolicy
  {
  protected:
    void sleepProducer();
    void wakeProducer();
    void sleepConsumer();
    void wakeConsumer();
    void wakeAllConsumers();
  };

ParticipationPolicy

  template <typename TaskType, typename ConsumerType, typename IdlePolicy>
  class ParticipationPolicy: public IdlePolicy
  {
  protected:
    NotParticipating(const ConsumerType& prototype);
    const unsigned numDynamicThreads(unsigned numThreads) const;
    template <typename Queue> bool participate(Queue&);
  };

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

Generated on Mon Nov 10 14:22:08 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo