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.
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. If the Jobs that are ready to run, i.e., all jobs it depends on have completed, the Scheduler choose 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().
-
Prior version 0.17 the Scheduler could not be recycled, i.e., if wait(void) or interruped(void) had been called, the behaviour of submit() was undefined.
- Since
- New in yat 0.13