+2019-12-02 Mike Crowe <mac@mcrowe.com>
+
+ * testsuite/30_threads/recursive_timed_mutex/try_lock_until/3.cc:
+ New test. Ensure that timed_mutex::try_lock_until actually times out
+ after the specified time when using both system_clock and
+ steady_clock.
+ * testsuite/30_threads/timed_mutex/try_lock_until/3.cc: New test.
+ Likewise but for recursive_timed_mutex.
+ * testsuite/30_threads/timed_mutex/try_lock_until/57641.cc: Template
+ test functions and use them to test both steady_clock and system_clock.
+ * testsuite/30_threads/unique_lock/locking/4.cc: Likewise. Wrap call
+ to timed_mutex::try_lock_until in VERIFY macro to check its return
+ value.
+
2019-11-30 Jonathan Wakely <jwakely@redhat.com>
* acinclude.m4 (GLIBCXX_ENABLE_FILESYSTEM_TS): Enable by default for
--- /dev/null
+// { dg-do run }
+// { dg-options "-pthread" }
+// { dg-require-effective-target c++14 }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <mutex>
+#include <thread>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+template <typename clock_type>
+void test()
+{
+ typedef std::recursive_timed_mutex mutex_type;
+
+ try
+ {
+ mutex_type m;
+ m.lock();
+ bool b;
+
+ std::thread t([&] {
+ try
+ {
+ using namespace std::chrono;
+ const auto timeout = 100ms;
+ const auto start = clock_type::now();
+ const auto b = m.try_lock_until(start + timeout);
+ const auto t = clock_type::now() - start;
+ VERIFY( !b );
+ VERIFY( t >= timeout );
+ }
+ catch (const std::system_error& e)
+ {
+ VERIFY( false );
+ }
+ });
+ t.join();
+ m.unlock();
+ }
+ catch (const std::system_error& e)
+ {
+ VERIFY( false );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+}
+
+int main()
+{
+ test<std::chrono::system_clock>();
+ test<std::chrono::steady_clock>();
+}
--- /dev/null
+// { dg-do run }
+// { dg-options "-pthread" }
+// { dg-require-effective-target c++14 }
+// { dg-require-effective-target pthread }
+// { dg-require-gthreads "" }
+
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <mutex>
+#include <thread>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+template <typename clock_type>
+void test()
+{
+ typedef std::timed_mutex mutex_type;
+
+ try
+ {
+ mutex_type m;
+ m.lock();
+ bool b;
+
+ std::thread t([&] {
+ try
+ {
+ using namespace std::chrono;
+ const auto timeout = 100ms;
+ const auto start = clock_type::now();
+ const auto b = m.try_lock_until(start + timeout);
+ const auto t = clock_type::now() - start;
+ VERIFY( !b );
+ VERIFY( t >= timeout );
+ }
+ catch (const std::system_error& e)
+ {
+ VERIFY( false );
+ }
+ });
+ t.join();
+ m.unlock();
+ }
+ catch (const std::system_error& e)
+ {
+ VERIFY( false );
+ }
+ catch (...)
+ {
+ VERIFY( false );
+ }
+}
+
+int main()
+{
+ test<std::chrono::system_clock>();
+ test<std::chrono::steady_clock>();
+}
std::timed_mutex mx;
bool locked = false;
+template <typename ClockType>
void f()
{
- locked = mx.try_lock_until(clock::now() + C::milliseconds(1));
+ locked = mx.try_lock_until(ClockType::now() + C::milliseconds(1));
}
-int main()
+template <typename ClockType>
+void test()
{
std::lock_guard<std::timed_mutex> l(mx);
- auto start = C::system_clock::now();
- std::thread t(f);
+ auto start = ClockType::now();
+ std::thread t(f<ClockType>);
t.join();
- auto stop = C::system_clock::now();
+ auto stop = ClockType::now();
VERIFY( (stop - start) < C::seconds(9) );
VERIFY( !locked );
}
+
+int main()
+{
+ test<C::system_clock>();
+ test<C::steady_clock>();
+}
#include <system_error>
#include <testsuite_hooks.h>
-int main()
+template <typename clock_type>
+void test()
{
typedef std::timed_mutex mutex_type;
typedef std::unique_lock<mutex_type> lock_type;
- typedef std::chrono::system_clock clock_type;
try
{
mutex_type m;
lock_type l(m, std::defer_lock);
- clock_type::time_point t = clock_type::now() + std::chrono::seconds(1);
+ const typename clock_type::time_point t = clock_type::now()
+ + std::chrono::seconds(1);
try
{
- l.try_lock_until(t);
+ VERIFY( l.try_lock_until(t) );
}
catch(const std::system_error&)
{
{
VERIFY( false );
}
+}
+int main()
+{
+ test<std::chrono::system_clock>();
+ test<std::chrono::steady_clock>();
return 0;
}