Line | |
---|
1 | // Copyright (C) 2001-2003 |
---|
2 | // William E. Kempf |
---|
3 | // |
---|
4 | // Permission to use, copy, modify, distribute and sell this software |
---|
5 | // and its documentation for any purpose is hereby granted without fee, |
---|
6 | // provided that the above copyright notice appear in all copies and |
---|
7 | // that both that copyright notice and this permission notice appear |
---|
8 | // in supporting documentation. William E. Kempf makes no representations |
---|
9 | // about the suitability of this software for any purpose. |
---|
10 | // It is provided "as is" without express or implied warranty. |
---|
11 | |
---|
12 | #include <boost/thread/thread.hpp> |
---|
13 | #include <boost/thread/xtime.hpp> |
---|
14 | #include <iostream> |
---|
15 | |
---|
16 | struct thread_alarm |
---|
17 | { |
---|
18 | thread_alarm(int secs) : m_secs(secs) { } |
---|
19 | void operator()() |
---|
20 | { |
---|
21 | boost::xtime xt; |
---|
22 | boost::xtime_get(&xt, boost::TIME_UTC); |
---|
23 | xt.sec += m_secs; |
---|
24 | |
---|
25 | boost::thread::sleep(xt); |
---|
26 | |
---|
27 | std::cout << "alarm sounded..." << std::endl; |
---|
28 | } |
---|
29 | |
---|
30 | int m_secs; |
---|
31 | }; |
---|
32 | |
---|
33 | int main(int argc, char* argv[]) |
---|
34 | { |
---|
35 | int secs = 5; |
---|
36 | std::cout << "setting alarm for 5 seconds..." << std::endl; |
---|
37 | thread_alarm alarm(secs); |
---|
38 | boost::thread thrd(alarm); |
---|
39 | thrd.join(); |
---|
40 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.