X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FTuto_Boost%2Fsrc%2Fcpp%2Fcore%2Fthread%2F02_thread_procedure_args.cpp;fp=WCudaMSE%2FTuto_Boost%2Fsrc%2Fcpp%2Fcore%2Fthread%2F02_thread_procedure_args.cpp;h=507765d95ca429a6772a78469fe331713eacde5d;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Tuto_Boost/src/cpp/core/thread/02_thread_procedure_args.cpp b/WCudaMSE/Tuto_Boost/src/cpp/core/thread/02_thread_procedure_args.cpp new file mode 100755 index 0000000..507765d --- /dev/null +++ b/WCudaMSE/Tuto_Boost/src/cpp/core/thread/02_thread_procedure_args.cpp @@ -0,0 +1,74 @@ +#include +#include + + +using std::cout; +using std::endl; + +using boost::thread; +using boost::chrono::milliseconds; +using boost::this_thread::sleep_for; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +void helloThread_ProcedureArgs(void); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +static void runnable(float x); + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +void helloThread_ProcedureArgs(void) + { + cout << "\nthread : procedure args : start" << endl; + + float x = 3.14; + thread threadRunnable(runnable, x); // x sera passer à runnable + + cout << "Waiting for thread ..." << endl; + + threadRunnable.join(); + + cout << "thread : procedure args : end" << endl; + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +void runnable(float x) + { + cout << "runnable : start" << endl; + cout << "x = " << x << endl; + + // Pretend to do something useful... + { + sleep_for(milliseconds(2000)); // from version 1.53 only + } + + cout << "runnable: end" << endl; + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +