SoDaRadio-5.0.3-master:8901fb5
SoDa_ThreadTest.cxx
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012, Matthew H. Reilly (kb1vc)
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in
13  the documentation and/or other materials provided with the
14  distribution.
15 
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #include "SoDaBase.hxx"
30 #include <string>
31 #include <iostream>
32 
33 namespace SoDaTest {
34  class ThN : public SoDa::SoDaThread {
35  public:
36  ThN() : SoDaThread("ThN") {};
37  std::string name;
38  void run() {
39  while(1) {
40  std::cerr << name << std::endl;
41  boost::this_thread::sleep(boost::posix_time::seconds(1));
42  }
43  }
44  };
45 
46  class Th0 : public ThN {
47  public:
48  Th0() { name = "zero"; }
49  };
50  class Th1 : public ThN {
51  public:
52  Th1() { name = "one"; }
53  };
54 }
55 
56 int main()
57 {
58  SoDaTest::Th0 t0;
59  SoDaTest::Th1 t1;
60 
61  t0.start();
62  t1.start();
63 
64  for(int i = 0; i < 3; i++) {
65  boost::this_thread::sleep(boost::posix_time::seconds(3));
66  std::cerr << "main" << std::endl;
67  }
68 }
The Baseclass for all SoDa objects, and useful commonly used classes.
The Thread baseclass for all SoDa thread objects.
Definition: SoDaBase.hxx:284
int main()
void start()
Execute the threads run loop.
Definition: SoDaBase.hxx:292
std::string name
SoDaThread(const std::string &oname)
Definition: SoDaBase.hxx:286
void run()
Each thread object must define its "run" loop.