| 1 | // Copyright (C) 2010 Vicente Botet |
|---|---|
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #define BOOST_THREAD_VERSION 2 |
| 7 | |
| 8 | #include <iostream> |
| 9 | #include <boost/thread/thread_only.hpp> |
| 10 | #include <boost/date_time.hpp> |
| 11 | |
| 12 | void workerFunc() |
| 13 | { |
| 14 | boost::posix_time::seconds workTime(3); |
| 15 | |
| 16 | std::cout << "Worker: running"<< std::endl; |
| 17 | |
| 18 | // Pretend to do something useful... |
| 19 | boost::this_thread::sleep(rel_time: workTime); |
| 20 | |
| 21 | std::cout << "Worker: finished"<< std::endl; |
| 22 | } |
| 23 | |
| 24 | int main() |
| 25 | { |
| 26 | std::cout << "main: startup"<< std::endl; |
| 27 | |
| 28 | boost::thread workerThread(workerFunc); |
| 29 | |
| 30 | std::cout << "main: waiting for thread"<< std::endl; |
| 31 | |
| 32 | workerThread.join(); |
| 33 | |
| 34 | std::cout << "main: done"<< std::endl; |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 |
