1 | #include <iostream> |
---|
2 | #include <string> |
---|
3 | #include <boost/thread/thread.hpp> |
---|
4 | |
---|
5 | using namespace std; |
---|
6 | void goodbye() |
---|
7 | { |
---|
8 | cout << "Goodbye World "; |
---|
9 | cout <<endl; |
---|
10 | } |
---|
11 | |
---|
12 | void hello(string msg) |
---|
13 | { |
---|
14 | cout << "Hello World "; |
---|
15 | cout << msg << ", I am a thread"<<std::endl; |
---|
16 | cout <<endl; |
---|
17 | boost::this_thread::at_thread_exit(&goodbye); |
---|
18 | } |
---|
19 | |
---|
20 | int main(int argc, const char * argv[]) |
---|
21 | { |
---|
22 | boost::thread t(&hello,"from me!"); |
---|
23 | t.join(); |
---|
24 | // insert code here... |
---|
25 | cout << "Hello again, World!\n"<<endl; |
---|
26 | return 0; |
---|
27 | |
---|
28 | } |
---|
29 | |
---|
30 | /// OUTPUT: |
---|
31 | /* |
---|
32 | Hello World from me!, I am a thread |
---|
33 | |
---|
34 | Goodbye World |
---|
35 | */ |
---|
36 | /// Program then hangs just before leaving the thread with |
---|
37 | /// Thread2: EXC_BAD_ACCESS(code=1, address=0x19) |
---|