libmoost
|
Allow a batch of jobs to be processed asyncronously whilst you wait. More...
#include <async_batch_processor.hpp>
Classes | |
class | batch_state |
Public Types | |
typedef boost::function0< void > | job_t |
typedef std::vector< job_t > | jobs_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 |
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.
typedef boost::function0<void> moost::thread::async_batch_processor::job_t |
Definition at line 98 of file async_batch_processor.hpp.
typedef std::vector<job_t> moost::thread::async_batch_processor::jobs_t |
Definition at line 99 of file async_batch_processor.hpp.
moost::thread::async_batch_processor::async_batch_processor | ( | size_t | num_threads | ) | [inline] |
Construct a new processor.
threadcnt | the number of threads that will be used by the dispatcher |
Definition at line 107 of file async_batch_processor.hpp.
void moost::thread::async_batch_processor::dispatch | ( | jobs_t & | jobs | ) | [inline] |
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.
jobs | A collection of jobs to be processed |
Definition at line 121 of file async_batch_processor.hpp.
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.
Definition at line 148 of file async_batch_processor.hpp.