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/condition_variable>
16 // class condition_variable;
18 // condition_variable(const condition_variable&) = delete;
21 #include <boost/thread/condition_variable.hpp>
22 #include <boost/thread/mutex.hpp>
23 #include <boost/thread/thread.hpp>
24 #include <boost/detail/lightweight_test.hpp>
26 #include "../../../timming.hpp"
28 #if defined BOOST_THREAD_USES_CHRONO
30 boost::condition_variable cv
;
38 typedef boost::chrono::steady_clock Clock
;
39 typedef boost::chrono::milliseconds milliseconds
;
40 typedef boost::chrono::nanoseconds nanoseconds
;
41 typedef boost::chrono::milliseconds ms
;
42 typedef boost::chrono::nanoseconds ns
;
44 const ms
max_diff(BOOST_THREAD_TEST_TIME_MS
);
49 boost::unique_lock
<boost::mutex
> lk(mut
);
53 Clock::time_point t0
= Clock::now();
54 Clock::time_point t
= t0
+ milliseconds(250);
55 while (test2
== 0 && cv
.wait_for(lk
, t
- Clock::now()) == boost::cv_status::no_timeout
) {}
56 Clock::time_point t1
= Clock::now();
59 assert(t1
- t0
< max_diff
);
64 nanoseconds d
= t1
- t0
- milliseconds(250);
65 std::cout
<< "diff= " << d
.count() << std::endl
;
66 std::cout
<< "max_diff= " << max_diff
.count() << std::endl
;
67 assert( d
< max_diff
);
72 std::cout
<< "ERROR exception" << __LINE__
<< std::endl
;
81 boost::unique_lock
<boost::mutex
> lk(mut
);
83 BOOST_TEST(test1
== 0);
86 BOOST_TEST(test1
!= 0);
92 std::cout
<< "ERROR exception" << __LINE__
<< std::endl
;
99 boost::unique_lock
<boost::mutex
> lk(mut
);
101 BOOST_TEST(test1
== 0);
104 BOOST_TEST(test1
!= 0);
109 std::cout
<< "ERROR exception" << __LINE__
<< std::endl
;
111 return boost::report_errors();
114 #error "Test not applicable: BOOST_THREAD_USES_CHRONO not defined for this platform as not supported"