X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=WCudaMSE%2FTuto_Boost%2Fsrc%2Fcpp%2Fcore%2Fthread%2F04_thread_objet_methode.cpp;fp=WCudaMSE%2FTuto_Boost%2Fsrc%2Fcpp%2Fcore%2Fthread%2F04_thread_objet_methode.cpp;h=b25af82e6f1aa31d45c6f6e64de2916090a93a9c;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Tuto_Boost/src/cpp/core/thread/04_thread_objet_methode.cpp b/WCudaMSE/Tuto_Boost/src/cpp/core/thread/04_thread_objet_methode.cpp new file mode 100755 index 0000000..b25af82 --- /dev/null +++ b/WCudaMSE/Tuto_Boost/src/cpp/core/thread/04_thread_objet_methode.cpp @@ -0,0 +1,67 @@ +#include +#include "Runnable.h" + +#include +#include + + + +using std::cout; +using std::endl; + +using boost::thread; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +void helloThread_Methode(void); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +void helloThread_Methode(void) + { + int x = 10; + int y = 100; + Runnable runnable(x, y); + + cout << "\nthread : methode : start" << endl; + + // arg1 : adresse de la methode run de la classe Runnable + // arg2 : adresse de l'objet sur lequel aller chercher la metode run + thread threadRunnable(&Runnable::run, &runnable); + + cout << "Waiting for thread ..." << endl; + + threadRunnable.join(); + cout << "thread : methode : end" << endl; + + cout << "[outside thread] : " << x << " + " << y << " = " << runnable.getResult() << endl; // give bad result cause runnable instance is passed by value to boost::thread + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +