Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Tuto_Boost / src / cpp / core / thread / 02_thread_procedure_args.cpp
1 #include <iostream>
2 #include <boost/thread.hpp>
3
4
5 using std::cout;
6 using std::endl;
7
8 using boost::thread;
9 using boost::chrono::milliseconds;
10 using boost::this_thread::sleep_for;
11
12 /*----------------------------------------------------------------------*\
13 |* Declaration *|
14 \*---------------------------------------------------------------------*/
15
16 /*--------------------------------------*\
17 |* Imported *|
18 \*-------------------------------------*/
19
20 /*--------------------------------------*\
21 |* Public *|
22 \*-------------------------------------*/
23
24 void helloThread_ProcedureArgs(void);
25
26 /*--------------------------------------*\
27 |* Private *|
28 \*-------------------------------------*/
29
30 static void runnable(float x);
31
32 /*----------------------------------------------------------------------*\
33 |* Implementation *|
34 \*---------------------------------------------------------------------*/
35
36 /*--------------------------------------*\
37 |* Public *|
38 \*-------------------------------------*/
39
40 void helloThread_ProcedureArgs(void)
41 {
42 cout << "\nthread : procedure args : start" << endl;
43
44 float x = 3.14;
45 thread threadRunnable(runnable, x); // x sera passer à runnable
46
47 cout << "Waiting for thread ..." << endl;
48
49 threadRunnable.join();
50
51 cout << "thread : procedure args : end" << endl;
52 }
53
54 /*--------------------------------------*\
55 |* Private *|
56 \*-------------------------------------*/
57
58 void runnable(float x)
59 {
60 cout << "runnable : start" << endl;
61 cout << "x = " << x << endl;
62
63 // Pretend to do something useful...
64 {
65 sleep_for(milliseconds(2000)); // from version 1.53 only
66 }
67
68 cout << "runnable: end" << endl;
69 }
70
71 /*----------------------------------------------------------------------*\
72 |* End *|
73 \*---------------------------------------------------------------------*/
74