Protium
Math and Design Features
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
protium_thread_tests.cxx
Go to the documentation of this file.
1 
5 
6 #include <iostream>
7 
8 
9 class Printer{
10  int fMember;
11 public:
12  Printer(const int& x) : fMember(x) {}
13  void Print(){std::cout<<"This is Printer: "<<fMember<<std::endl;}
14 };
15 
16 
17 template< template<class, class>class ThreadingPolicy>
18 class ThreadedObject : public ThreadingPolicy<Printer, Protium::Threads::Mutex>, public Printer {
19  typedef typename ThreadingPolicy<Printer, Protium::Threads::Mutex>::Lock lock;
20 
21 public:
22  ThreadedObject(const int& x) : Printer(x) {}
23  void Print(){
24  lock x(*this);
25  Printer::Print();
26  }
27 };
28 
29 typedef ThreadedObject<Protium::Threads::InSingleThread> Single;
30 typedef ThreadedObject<Protium::Threads::InstanceLocked> Multi1;
31 typedef ThreadedObject<Protium::Threads::StaticLocked> Multi2;
32 
33 
34 
35 
36 int main(int argc, char* argv[]){
37 
38  Single x(1);
39  x.Print();
40 
41  Multi1 y(2);
42  y.Print();
43 
44  Multi2 z(3);
45  z.Print();
46 
47 }
ThreadedObject< Protium::Threads::InSingleThread > Single
ThreadedObject< Protium::Threads::StaticLocked > Multi2
int main(int argc, char *argv[])
ThreadedObject< Protium::Threads::InstanceLocked > Multi1