|
Last change
on this file since 29 was
29,
checked in by landauf, 17 years ago
|
|
updated boost from 1_33_1 to 1_34_1
|
|
File size:
806 bytes
|
| Line | |
|---|
| 1 | // Copyright (C) 2001-2003 |
|---|
| 2 | // William E. Kempf |
|---|
| 3 | // |
|---|
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
|---|
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 6 | |
|---|
| 7 | #include <boost/thread/thread.hpp> |
|---|
| 8 | #include <boost/thread/xtime.hpp> |
|---|
| 9 | #include <iostream> |
|---|
| 10 | |
|---|
| 11 | struct thread_alarm |
|---|
| 12 | { |
|---|
| 13 | thread_alarm(int secs) : m_secs(secs) { } |
|---|
| 14 | void operator()() |
|---|
| 15 | { |
|---|
| 16 | boost::xtime xt; |
|---|
| 17 | boost::xtime_get(&xt, boost::TIME_UTC); |
|---|
| 18 | xt.sec += m_secs; |
|---|
| 19 | |
|---|
| 20 | boost::thread::sleep(xt); |
|---|
| 21 | |
|---|
| 22 | std::cout << "alarm sounded..." << std::endl; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | int m_secs; |
|---|
| 26 | }; |
|---|
| 27 | |
|---|
| 28 | int main(int argc, char* argv[]) |
|---|
| 29 | { |
|---|
| 30 | int secs = 5; |
|---|
| 31 | std::cout << "setting alarm for 5 seconds..." << std::endl; |
|---|
| 32 | thread_alarm alarm(secs); |
|---|
| 33 | boost::thread thrd(alarm); |
|---|
| 34 | thrd.join(); |
|---|
| 35 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.