yat  0.14.5pre
Classes | Public Member Functions | List of all members
theplu::yat::utility::Scheduler Class Reference

Handle a number of jobs and send them to threads. More...

#include <yat/utility/Scheduler.h>

Classes

class  Job
 

Public Member Functions

 Scheduler (unsigned int threads)
 constructor More...
 
void add_dependency (boost::shared_ptr< Job > job, boost::shared_ptr< Job > prerequisite)
 add a dependency rule More...
 
void interrupt (void)
 interrrupt all jobs
 
void submit (boost::shared_ptr< Job > job)
 submit a job to Scheduler More...
 
void wait (void)
 wait for all jobs to finish
 

Detailed Description

Handle a number of jobs and send them to threads.

Scheduler starts a (user defined) number of threads and handles a series of Jobs. The Jobs can have dependencies, such that Job X must finish before Job Y can run, and the Scheduler takes care of these dependencies. Here is a small code example in which two threads are used to process the four jobs, MyJob. The jobs have a dependency that job4 can not run until the three first jobs have completed.

Scheduler scheduler(2);
boost::shared_ptr<MyJob> job1(new MyJob("Hello"));
boost::shared_ptr<MyJob> job2(new MyJob(" "));
boost::shared_ptr<MyJob> job3(new MyJob("World"));
boost::shared_ptr<MyJob> job4(new MyJob("\n"));
scheduler.add_dependency(job4, job1);
scheduler.add_dependency(job4, job2);
scheduler.add_dependency(job4, job3);
scheduler.submit(job4);
scheduler.wait();

The Scheduler sends jobs to the workers taking into account dependencies, priorities and the order in which the Scheduler has seen the Jobs. Of the Jobs that are ready to run, i.e., all jobs it depends on have completed, the Scheduler chose the Job with highest priority. If two Jobs have the same priority, the Scheduler sends them in the order of appearance, i.e., if the Scheduler saw Job X before Job Y, Job X is run before Job X.

Note
In the current implementation all submitted jobs have to be completed before the Scheduler goes out of scope, which can be accomplished by calling wait() or interrupt().
Currently, the Scheduler cannot be recycled, i.e., if wait(void) or interruped(void) have been called, the behaviour of submit() is undefined.
Since
New in yat 0.13

Constructor & Destructor Documentation

theplu::yat::utility::Scheduler::Scheduler ( unsigned int  threads)

constructor

Parameters
threadsnumber of threads that are used

Member Function Documentation

void theplu::yat::utility::Scheduler::add_dependency ( boost::shared_ptr< Job job,
boost::shared_ptr< Job prerequisite 
)

add a dependency rule

Add a dependency that Job prerequisite has to complete before Job job is run.

void theplu::yat::utility::Scheduler::submit ( boost::shared_ptr< Job job)

submit a job to Scheduler

If job depends on other jobs, they are also submitted to the Scheduler.

Note
If wait() or interrupt() have been called, the behaviour of submit() is undefined.

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

Generated on Tue Sep 26 2017 02:33:31 for yat by  doxygen 1.8.5