libmoost
moost::thread::async_batch_processor Class Reference

Allow a batch of jobs to be processed asyncronously whilst you wait. More...

#include <async_batch_processor.hpp>

Collaboration diagram for moost::thread::async_batch_processor:

List of all members.

Classes

class  batch_state

Public Types

typedef boost::function0< void > job_t
typedef std::vector< job_tjobs_t

Public Member Functions

 async_batch_processor (size_t num_threads)
 Construct a new processor.
void dispatch (jobs_t &jobs)
 Dispatch worker threads to process jobs.

Static Private Member Functions

static void handler (job_t &job, boost::shared_ptr< batch_state > state)

Private Attributes

worker_group m_wg

Detailed Description

Allow a batch of jobs to be processed asyncronously whilst you wait.

There are times when you have a batch of data that needs to be processed and you want to process things asynchronously to maximise CPU usage.

The premise behind how it works is pretty simple; you create a collection of jobs where a job is a functor loaded with your data and logic to process the data. You then dispatch threads to process the jobs. The jobs will then be processed asyncronously but the dispatcher will block until all the jobs are processed.

It's like you are sending out a bunch of workers to dig a hole for you whilst you sit down and have a nice cup of tea :)

Definition at line 59 of file async_batch_processor.hpp.


Member Typedef Documentation

typedef boost::function0<void> moost::thread::async_batch_processor::job_t

Definition at line 98 of file async_batch_processor.hpp.

Definition at line 99 of file async_batch_processor.hpp.


Constructor & Destructor Documentation

Construct a new processor.

Parameters:
threadcntthe number of threads that will be used by the dispatcher

Definition at line 107 of file async_batch_processor.hpp.


Member Function Documentation

Dispatch worker threads to process jobs.

The dispatcher will dispatch threads to process your jobs and then wait until they are all done. Only then will it return to the caller.

Parameters:
jobsA collection of jobs to be processed

Definition at line 121 of file async_batch_processor.hpp.

Here is the call graph for this function:

static void moost::thread::async_batch_processor::handler ( job_t job,
boost::shared_ptr< batch_state state 
) [inline, static, private]

Definition at line 139 of file async_batch_processor.hpp.

Here is the caller graph for this function:


Member Data Documentation


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