]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //===----------------------------------------------------------------------===// |
2 | // | |
3 | // The LLVM Compiler Infrastructure | |
4 | // | |
5 | // This file is dual licensed under the MIT and the University of Illinois Open | |
6 | // Source Licenses. See LICENSE.TXT for details. | |
7 | // | |
8 | //===----------------------------------------------------------------------===// | |
9 | // Copyright (C) 2011 Vicente J. Botet Escriba | |
10 | // | |
11 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
12 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
13 | ||
14 | // <boost/thread/thread.hpp> | |
15 | ||
16 | // thread::id this_thread::get_id(); | |
17 | ||
18 | #include <boost/thread/thread_only.hpp> | |
19 | #include <cstdlib> | |
20 | #include <algorithm> | |
21 | ||
22 | #include <boost/detail/lightweight_test.hpp> | |
23 | ||
24 | #if defined BOOST_THREAD_USES_CHRONO | |
25 | ||
26 | int main() | |
27 | { | |
28 | { | |
29 | typedef boost::chrono::system_clock Clock; | |
30 | typedef Clock::time_point time_point; | |
31 | boost::chrono::milliseconds ms(500); | |
32 | time_point t0 = Clock::now(); | |
33 | boost::this_thread::sleep_for(ms); | |
34 | time_point t1 = Clock::now(); | |
35 | boost::chrono::nanoseconds ns = (t1 - t0) - ms; | |
36 | boost::chrono::nanoseconds err = ms / 100; | |
37 | // The time slept is within 1% of 500ms | |
38 | // This test is spurious as it depends on the time the thread system switches the threads | |
39 | BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count()); | |
40 | //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count()); | |
41 | } | |
42 | { | |
43 | typedef boost::chrono::system_clock Clock; | |
44 | typedef Clock::time_point time_point; | |
45 | boost::chrono::milliseconds ms(500); | |
46 | time_point t0 = Clock::now(); | |
47 | boost::this_thread::no_interruption_point::sleep_for(ms); | |
48 | time_point t1 = Clock::now(); | |
49 | boost::chrono::nanoseconds ns = (t1 - t0) - ms; | |
50 | boost::chrono::nanoseconds err = ms / 100; | |
51 | // The time slept is within 1% of 500ms | |
52 | // This test is spurious as it depends on the time the thread system switches the threads | |
53 | BOOST_TEST((std::max)(ns.count(), -ns.count()) < (err+boost::chrono::milliseconds(1000)).count()); | |
54 | //BOOST_TEST(std::abs(static_cast<long>(ns.count())) < (err+boost::chrono::milliseconds(1000)).count()); | |
55 | } | |
56 | return boost::report_errors(); | |
57 | ||
58 | } | |
59 | ||
60 | #else | |
61 | #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported" | |
62 | #endif | |
63 |