Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Tuto_Boost / src / cpp / core / thread / 04_thread_objet_methode.cpp
1 #include <iostream>
2 #include "Runnable.h"
3
4 #include <boost/thread.hpp>
5 #include <boost/date_time.hpp>
6
7
8
9 using std::cout;
10 using std::endl;
11
12 using boost::thread;
13
14 /*----------------------------------------------------------------------*\
15 |* Declaration *|
16 \*---------------------------------------------------------------------*/
17
18 /*--------------------------------------*\
19 |* Imported *|
20 \*-------------------------------------*/
21
22 /*--------------------------------------*\
23 |* Public *|
24 \*-------------------------------------*/
25
26 void helloThread_Methode(void);
27
28 /*--------------------------------------*\
29 |* Private *|
30 \*-------------------------------------*/
31
32 /*----------------------------------------------------------------------*\
33 |* Implementation *|
34 \*---------------------------------------------------------------------*/
35
36 /*--------------------------------------*\
37 |* Public *|
38 \*-------------------------------------*/
39
40 void helloThread_Methode(void)
41 {
42 int x = 10;
43 int y = 100;
44 Runnable runnable(x, y);
45
46 cout << "\nthread : methode : start" << endl;
47
48 // arg1 : adresse de la methode run de la classe Runnable
49 // arg2 : adresse de l'objet sur lequel aller chercher la metode run
50 thread threadRunnable(&Runnable::run, &runnable);
51
52 cout << "Waiting for thread ..." << endl;
53
54 threadRunnable.join();
55 cout << "thread : methode : end" << endl;
56
57 cout << "[outside thread] : " << x << " + " << y << " = " << runnable.getResult() << endl; // give bad result cause runnable instance is passed by value to boost::thread
58 }
59
60 /*--------------------------------------*\
61 |* Private *|
62 \*-------------------------------------*/
63
64 /*----------------------------------------------------------------------*\
65 |* End *|
66 \*---------------------------------------------------------------------*/
67