Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Tuto_Boost / src / cpp / core / thread / 03_thread_objet.cpp
diff --git a/WCudaMSE/Tuto_Boost/src/cpp/core/thread/03_thread_objet.cpp b/WCudaMSE/Tuto_Boost/src/cpp/core/thread/03_thread_objet.cpp
new file mode 100755 (executable)
index 0000000..3575e5a
--- /dev/null
@@ -0,0 +1,68 @@
+#include <iostream>\r
+#include <boost/thread.hpp>\r
+#include <boost/date_time.hpp>\r
+#include "Runnable.h"\r
+\r
+\r
+using std::cout;\r
+using std::endl;\r
+\r
+using boost::thread;\r
+using boost::ref;\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    Declaration                                     *|\r
+ \*---------------------------------------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Imported                *|\r
+ \*-------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Public                  *|\r
+ \*-------------------------------------*/\r
+\r
+void helloThread_Objet(void);\r
+\r
+/*--------------------------------------*\\r
+ |*            Private                 *|\r
+ \*-------------------------------------*/\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    Implementation                                  *|\r
+ \*---------------------------------------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Public                  *|\r
+ \*-------------------------------------*/\r
+\r
+void helloThread_Objet(void)\r
+    {\r
+    int x = 10;\r
+    int y = 100;\r
+    Runnable runnable(x, y);\r
+\r
+    cout << "\nthread : objet : start" << endl;\r
+\r
+    // A very important consideration when using functors with boost threads is that the thread constructor takes the functor parameter by value !!\r
+   // boost::thread threadRunnable(runnable);\r
+\r
+    // Solution: Here runnable is passed by reference (not a copy)\r
+   thread threadRunnable(ref(runnable)); // use foncteur runnable() of Runnable\r
+\r
+    cout << "Waiting for thread ..." << endl;\r
+\r
+    threadRunnable.join();\r
+    cout << "[outside thread] : " << x << " + " << y << " = " << runnable.getResult() << endl; // give bad result if  runnable  is passed by value to  boost::thread\r
+\r
+    cout << "thread : objet : end" << endl;\r
+    }\r
+\r
+/*--------------------------------------*\\r
+ |*            Private                 *|\r
+ \*-------------------------------------*/\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    End                                             *|\r
+ \*---------------------------------------------------------------------*/\r
+\r