1 | #include <iostream> |
---|
2 | #include <memory> |
---|
3 | #include <boost/thread.hpp> |
---|
4 | |
---|
5 | class Test { |
---|
6 | private: |
---|
7 | std::shared_ptr<boost::thread> m_thread; |
---|
8 | public: |
---|
9 | void test(); |
---|
10 | void threadEntry(); |
---|
11 | }; |
---|
12 | |
---|
13 | void Test::test() { |
---|
14 | std::cout << "starting\n"; |
---|
15 | m_thread.reset(new boost::thread(boost::bind(&Test::threadEntry, this))); |
---|
16 | m_thread->join(); |
---|
17 | m_thread.reset(); |
---|
18 | std::cout << "finishing\n"; |
---|
19 | } |
---|
20 | |
---|
21 | void Test::threadEntry() { |
---|
22 | std::cout << "enter thread\n"; |
---|
23 | boost::this_thread::sleep(boost::posix_time::seconds(1)); |
---|
24 | std::cout << "exit thread\n"; |
---|
25 | } |
---|
26 | |
---|
27 | int main() { |
---|
28 | Test test; |
---|
29 | test.test(); |
---|
30 | } |
---|