Ticket #42496: threadtest.cpp

File threadtest.cpp, 602 bytes (added by trojanfoe@…, 11 years ago)

Test source code

Line 
1#include <iostream>
2#include <memory>
3#include <boost/thread.hpp>
4
5class Test {
6private:
7    std::shared_ptr<boost::thread> m_thread;
8public:
9    void test();
10    void threadEntry();
11};
12
13void 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
21void 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
27int main() {
28    Test test;
29    test.test();
30}