Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Tuto_Boost / src / cpp / core / thread / 01_thread_procedure.cpp
1 #include <iostream>
2 //#include <thread> // include with c++11 (#CXXFLAGS+= -std=c++0x)
3
4 using std::cout;
5 using std::endl;
6
7 #include <boost/thread.hpp>
8 #include <boost/date_time.hpp>
9
10 using boost::thread;
11 using boost::posix_time::seconds;
12 using boost::this_thread::sleep;
13 using boost::this_thread::get_id;
14
15
16 /*----------------------------------------------------------------------*\
17 |* Declaration *|
18 \*---------------------------------------------------------------------*/
19
20 /*--------------------------------------*\
21 |* Imported *|
22 \*-------------------------------------*/
23
24 /*--------------------------------------*\
25 |* Public *|
26 \*-------------------------------------*/
27
28 void helloThread_Procedure(void);
29
30 /*--------------------------------------*\
31 |* Private *|
32 \*-------------------------------------*/
33
34 static void runnable(void);
35
36 /*----------------------------------------------------------------------*\
37 |* Implementation *|
38 \*---------------------------------------------------------------------*/
39
40 /*--------------------------------------*\
41 |* Public *|
42 \*-------------------------------------*/
43
44 // http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html
45
46 void helloThread_Procedure(void)
47 {
48 cout << "\nthread : procedure : start" << endl;
49
50 thread threadRunnable(runnable);
51
52 cout << "Waiting for thread ..." << endl;
53
54 threadRunnable.join();
55
56 cout << "thread : procedure : end " << endl;
57 }
58
59 /*--------------------------------------*\
60 |* Private *|
61 \*-------------------------------------*/
62
63 void runnable(void)
64 {
65 cout << "runnable : start" << endl;
66 cout<<"Hello from thread : id : "<<get_id() << endl;
67
68 // Pretend to do something useful...
69 {
70 seconds workTime(3);
71 sleep(workTime);
72 }
73
74 cout << "runnable: end" << endl;
75 }
76
77 /*----------------------------------------------------------------------*\
78 |* End *|
79 \*---------------------------------------------------------------------*/
80