2 //#include <thread> // include with c++11 (#CXXFLAGS+= -std=c++0x)
7 #include <boost/thread.hpp>
8 #include <boost/date_time.hpp>
11 using boost::posix_time::seconds
;
12 using boost::this_thread::sleep
;
13 using boost::this_thread::get_id
;
16 /*----------------------------------------------------------------------*\
18 \*---------------------------------------------------------------------*/
20 /*--------------------------------------*\
22 \*-------------------------------------*/
24 /*--------------------------------------*\
26 \*-------------------------------------*/
28 void helloThread_Procedure(void);
30 /*--------------------------------------*\
32 \*-------------------------------------*/
34 static void runnable(void);
36 /*----------------------------------------------------------------------*\
38 \*---------------------------------------------------------------------*/
40 /*--------------------------------------*\
42 \*-------------------------------------*/
44 // http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html
46 void helloThread_Procedure(void)
48 cout
<< "\nthread : procedure : start" << endl
;
50 thread
threadRunnable(runnable
);
52 cout
<< "Waiting for thread ..." << endl
;
54 threadRunnable
.join();
56 cout
<< "thread : procedure : end " << endl
;
59 /*--------------------------------------*\
61 \*-------------------------------------*/
65 cout
<< "runnable : start" << endl
;
66 cout
<<"Hello from thread : id : "<<get_id() << endl
;
68 // Pretend to do something useful...
74 cout
<< "runnable: end" << endl
;
77 /*----------------------------------------------------------------------*\
79 \*---------------------------------------------------------------------*/