source: trunk/test/scheduler.cc @ 3417

Last change on this file since 3417 was 3417, checked in by Peter, 4 years ago

updating copyright statements

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: scheduler.cc 3417 2015-05-25 01:35:59Z peter $
2
3/*
4  Copyright (C) 2014, 2015 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include <config.h>
23
24#include "Suite.h"
25
26#include "yat/utility/Scheduler.h"
27
28#include <boost/make_shared.hpp>
29#include <boost/shared_ptr.hpp>
30
31#include <cstdlib>
32#include <iostream>
33#include <set>
34#include <unistd.h>
35
36using namespace theplu::yat;
37using namespace theplu::yat::utility;
38
39class Sleeper : public Scheduler::Job
40{
41public:
42  Sleeper(int t) : time_(t) {}
43  void operator()(void)
44  {
45    sleep(time_);
46    std::cout << "Have slept for " << time_ << " seconds" << std::endl;
47  }
48private:
49  int time_;
50};
51
52
53int main(int argc, char* argv[])
54{
55  test::Suite suite(argc, argv);
56
57  Scheduler scheduler(2);
58  std::vector<boost::shared_ptr<Sleeper> > sleeper;
59  sleeper.reserve(4);
60  sleeper.push_back(boost::make_shared<Sleeper>(1));
61  sleeper.push_back(boost::make_shared<Sleeper>(10));
62  scheduler.submit(sleeper[1]);
63  sleeper.push_back(boost::make_shared<Sleeper>(2));
64  scheduler.add_dependency(sleeper[2], sleeper[0]);
65  sleeper.push_back(boost::make_shared<Sleeper>(3));
66
67  // not strictly needed since sleeper2 depends on sleeper0,
68  // but... this is a test
69  scheduler.add_dependency(sleeper[3], sleeper[0]);
70  scheduler.add_dependency(sleeper[3], sleeper[1]);
71  scheduler.add_dependency(sleeper[3], sleeper[2]);
72
73  scheduler.submit(sleeper[3]);
74  scheduler.wait();
75  return suite.return_value();
76}
Note: See TracBrowser for help on using the repository browser.