1 |
|
---|
2 | #include <iostream>
|
---|
3 | #include <boost/thread.hpp>
|
---|
4 | #include <boost/date_time.hpp>
|
---|
5 |
|
---|
6 | void workerFunc()
|
---|
7 | {
|
---|
8 | boost::posix_time::seconds workTime(3);
|
---|
9 |
|
---|
10 | std::cout << "Worker: running" << std::endl;
|
---|
11 |
|
---|
12 | // Pretend to do something useful...
|
---|
13 | boost::this_thread::sleep(workTime);
|
---|
14 |
|
---|
15 | std::cout << "Worker: finished" << std::endl;
|
---|
16 | }
|
---|
17 |
|
---|
18 | int main(int argc, char* argv[])
|
---|
19 | {
|
---|
20 | std::cout << "main: startup" << std::endl;
|
---|
21 |
|
---|
22 | boost::thread workerThread(workerFunc);
|
---|
23 |
|
---|
24 | std::cout << "main: waiting for thread" << std::endl;
|
---|
25 |
|
---|
26 | workerThread.join();
|
---|
27 |
|
---|
28 | std::cout << "main: done" << std::endl;
|
---|
29 |
|
---|
30 | return 0;
|
---|
31 | }
|
---|