]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/test/threads/this_thread/sleep_for/sleep_for_pass.cpp
1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
9 // Copyright (C) 2011 Vicente J. Botet Escriba
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)
14 // <boost/thread/thread.hpp>
16 // thread::id this_thread::get_id();
18 #include <boost/thread/thread_only.hpp>
22 #include <boost/detail/lightweight_test.hpp>
24 #if defined BOOST_THREAD_USES_CHRONO
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());
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());
56 return boost::report_errors();
61 #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"