2 // { dg-additional-options "-pthread" { target pthread } }
3 // { dg-require-effective-target c++11 }
4 // { dg-require-gthreads "" }
6 // Copyright (C) 2010-2023 Free Software Foundation, Inc.
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 3, or (at your option)
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING3. If not see
21 // <http://www.gnu.org/licenses/>.
24 #include <condition_variable>
25 #include <system_error>
26 #include <testsuite_hooks.h>
30 Mutex() : locked(false) { }
53 template <typename ClockType
>
58 std::chrono::microseconds
ms(500);
59 std::condition_variable_any c1
;
63 auto then
= ClockType::now();
64 std::cv_status result
= c1
.wait_until(m
, then
+ ms
);
65 VERIFY( result
== std::cv_status::timeout
);
66 VERIFY( (ClockType::now() - then
) >= ms
);
69 catch (const std::system_error
& e
)
79 /* User defined clock that ticks in two-thousandths of a second
80 forty-two minutes ahead of steady_clock. */
81 struct user_defined_clock
83 typedef std::chrono::steady_clock::rep rep
;
84 typedef std::ratio
<1, 2000> period
;
85 typedef std::chrono::duration
<rep
, period
> duration
;
86 typedef std::chrono::time_point
<user_defined_clock
> time_point
;
88 static constexpr bool is_steady
= true;
90 static time_point
now() noexcept
92 using namespace std::chrono
;
93 const auto steady_since_epoch
= steady_clock::now().time_since_epoch();
94 const auto user_since_epoch
= duration_cast
<duration
>(steady_since_epoch
);
95 return time_point(user_since_epoch
+ minutes(42));
101 test01
<std::chrono::steady_clock
>();
102 test01
<std::chrono::system_clock
>();
103 test01
<user_defined_clock
>();