Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Tuto_Boost / src / cpp / core / thread / Runnable.h
1 #ifndef RUNNABLE_H_
2 #define RUNNABLE_H_
3
4 #include <iostream>
5 #include <boost/date_time.hpp>
6 #include <boost/thread.hpp>
7
8 using std::cout;
9 using std::endl;
10
11 using boost::posix_time::seconds;
12 using boost::this_thread::sleep;
13
14 /*----------------------------------------------------------------------*\
15 |* Declaration *|
16 \*---------------------------------------------------------------------*/
17
18 /*--------------------------------------*\
19 |* Public *|
20 \*-------------------------------------*/
21
22 class Runnable
23 {
24 public:
25
26 Runnable(int a, int b)
27 {
28 // inputs
29 this->a = a;
30 this->b = b;
31
32 // ouputs
33 this->result = -1;
34 }
35
36 virtual ~Runnable(void)
37 {
38 // rien
39 }
40
41 /**
42 * Foncteur
43 */
44 void operator()()
45 {
46 cout << "runnable : foncteur : start" << endl;
47 work();
48 cout << "runnable : foncteur : end" << endl;
49 }
50
51 void run(void)
52 {
53 cout << "runnable : methode : start" << endl;
54 work();
55 cout << "runnable : methode : end" << endl;
56 }
57
58 int getResult(void)
59 {
60 return this->result;
61 }
62
63 private:
64
65 /**
66 * common to work and operator()
67 */
68 void work(void)
69 {
70
71 this->result = a + b;
72 cout << "[inside thread] : " << a << " + " << b << " = " << result << endl;
73 // Pretend to do something useful...
74 {
75 seconds workTime(3);
76 sleep(workTime);
77 }
78 }
79
80 private:
81
82 int a;
83 int b;
84 int result;
85 };
86
87 #endif
88
89 /*----------------------------------------------------------------------*\
90 |* End *|
91 \*---------------------------------------------------------------------*/