X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FTuto_Boost%2Fsrc%2Fcpp%2Fcore%2Fthread%2FRunnable.h;fp=WCudaMSE%2FTuto_Boost%2Fsrc%2Fcpp%2Fcore%2Fthread%2FRunnable.h;h=241db4db86214a89710feacd27951450ff146dbe;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Tuto_Boost/src/cpp/core/thread/Runnable.h b/WCudaMSE/Tuto_Boost/src/cpp/core/thread/Runnable.h new file mode 100755 index 0000000..241db4d --- /dev/null +++ b/WCudaMSE/Tuto_Boost/src/cpp/core/thread/Runnable.h @@ -0,0 +1,91 @@ +#ifndef RUNNABLE_H_ +#define RUNNABLE_H_ + +#include +#include +#include + +using std::cout; +using std::endl; + +using boost::posix_time::seconds; +using boost::this_thread::sleep; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +class Runnable + { + public: + + Runnable(int a, int b) + { + // inputs + this->a = a; + this->b = b; + + // ouputs + this->result = -1; + } + + virtual ~Runnable(void) + { + // rien + } + + /** + * Foncteur + */ + void operator()() + { + cout << "runnable : foncteur : start" << endl; + work(); + cout << "runnable : foncteur : end" << endl; + } + + void run(void) + { + cout << "runnable : methode : start" << endl; + work(); + cout << "runnable : methode : end" << endl; + } + + int getResult(void) + { + return this->result; + } + + private: + + /** + * common to work and operator() + */ + void work(void) + { + + this->result = a + b; + cout << "[inside thread] : " << a << " + " << b << " = " << result << endl; + // Pretend to do something useful... + { + seconds workTime(3); + sleep(workTime); + } + } + + private: + + int a; + int b; + int result; + }; + +#endif + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/