2 #include <boost/thread.hpp>
3 #include <boost/date_time.hpp>
13 /*----------------------------------------------------------------------*\
15 \*---------------------------------------------------------------------*/
17 /*--------------------------------------*\
19 \*-------------------------------------*/
21 /*--------------------------------------*\
23 \*-------------------------------------*/
25 void helloThread_Objet(void);
27 /*--------------------------------------*\
29 \*-------------------------------------*/
31 /*----------------------------------------------------------------------*\
33 \*---------------------------------------------------------------------*/
35 /*--------------------------------------*\
37 \*-------------------------------------*/
39 void helloThread_Objet(void)
43 Runnable
runnable(x
, y
);
45 cout
<< "\nthread : objet : start" << endl
;
47 // A very important consideration when using functors with boost threads is that the thread constructor takes the functor parameter by value !!
48 // boost::thread threadRunnable(runnable);
50 // Solution: Here runnable is passed by reference (not a copy)
51 thread
threadRunnable(ref(runnable
)); // use foncteur runnable() of Runnable
53 cout
<< "Waiting for thread ..." << endl
;
55 threadRunnable
.join();
56 cout
<< "[outside thread] : " << x
<< " + " << y
<< " = " << runnable
.getResult() << endl
; // give bad result if runnable is passed by value to boost::thread
58 cout
<< "thread : objet : end" << endl
;
61 /*--------------------------------------*\
63 \*-------------------------------------*/
65 /*----------------------------------------------------------------------*\
67 \*---------------------------------------------------------------------*/