summaryrefslogtreecommitdiffstats
path: root/libcxx/test/thread
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2013-09-21 01:49:28 +0000
committerHoward Hinnant <hhinnant@apple.com>2013-09-21 01:49:28 +0000
commitead6f1699dcda74528393b328250cbcb47fb1211 (patch)
tree9422739146cefb7921346f756b46e26dbd92c42b /libcxx/test/thread
parentb1c82cd09022f5e94f1d6c20a8d9182d7dd68abc (diff)
downloadbcm5719-llvm-ead6f1699dcda74528393b328250cbcb47fb1211.tar.gz
bcm5719-llvm-ead6f1699dcda74528393b328250cbcb47fb1211.zip
N3659: Shared locking in C++ Revision 2, c++1y only
llvm-svn: 191127
Diffstat (limited to 'libcxx/test/thread')
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp34
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp30
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp26
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp37
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp33
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp79
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp28
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp27
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp79
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp79
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp72
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp77
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp68
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp73
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp73
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp60
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp43
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp44
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp51
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/mutex.pass.cpp36
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/op_bool.pass.cpp36
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/owns_lock.pass.cpp36
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/types.pass.cpp29
-rw-r--r--libcxx/test/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.mod/release.pass.cpp2
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/nothing_to_do.pass.cpp12
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/assign.fail.cpp27
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/copy.fail.cpp26
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/default.pass.cpp23
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/lock.pass.cpp52
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/lock_shared.pass.cpp75
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock.pass.cpp56
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_for.pass.cpp71
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared.pass.cpp60
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared_for.pass.cpp78
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared_until.pass.cpp78
-rw-r--r--libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_until.pass.cpp71
36 files changed, 1780 insertions, 1 deletions
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp
new file mode 100644
index 00000000000..0bd347d0ba4
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_assign.fail.cpp
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// shared_lock& operator=(shared_lock const&) = delete;
+
+#include <shared_mutex>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m0;
+std::shared_mutex m1;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<std::shared_mutex> lk0(m0);
+ std::shared_lock<std::shared_mutex> lk1(m1);
+ lk1 = lk0;
+#else
+# error
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp
new file mode 100644
index 00000000000..66cec9ec58b
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/copy_ctor.fail.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// shared_lock(shared_lock const&) = delete;
+
+#include <shared_mutex>
+
+#if _LIBCPP_STD_VER > 11
+std::shared_mutex m;
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<std::shared_mutex> lk0(m);
+ std::shared_lock<std::shared_mutex> lk = lk0;
+#else
+# error
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp
new file mode 100644
index 00000000000..2adef5f76f9
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// shared_lock();
+
+#include <shared_mutex>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<std::shared_mutex> ul;
+ assert(!ul.owns_lock());
+ assert(ul.mutex() == nullptr);
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp
new file mode 100644
index 00000000000..1fcc98fce96
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// shared_lock& operator=(shared_lock&& u);
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m0;
+std::shared_mutex m1;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<std::shared_mutex> lk0(m0);
+ std::shared_lock<std::shared_mutex> lk1(m1);
+ lk1 = std::move(lk0);
+ assert(lk1.mutex() == &m0);
+ assert(lk1.owns_lock() == true);
+ assert(lk0.mutex() == nullptr);
+ assert(lk0.owns_lock() == false);
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp
new file mode 100644
index 00000000000..7e801da20f2
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// shared_lock(shared_lock&& u);
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+std::shared_mutex m;
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<std::shared_mutex> lk0(m);
+ std::shared_lock<std::shared_mutex> lk = std::move(lk0);
+ assert(lk.mutex() == &m);
+ assert(lk.owns_lock() == true);
+ assert(lk0.mutex() == nullptr);
+ assert(lk0.owns_lock() == false);
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp
new file mode 100644
index 00000000000..fd1dad42657
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// explicit shared_lock(mutex_type& m);
+
+#include <shared_mutex>
+#include <thread>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f()
+{
+ time_point t0 = Clock::now();
+ time_point t1;
+ {
+ std::shared_lock<std::shared_mutex> ul(m);
+ t1 = Clock::now();
+ }
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+void g()
+{
+ time_point t0 = Clock::now();
+ time_point t1;
+ {
+ std::shared_lock<std::shared_mutex> ul(m);
+ t1 = Clock::now();
+ }
+ ns d = t1 - t0;
+ assert(d < ms(50)); // within 50ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f));
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ m.lock_shared();
+ for (auto& t : v)
+ t = std::thread(g);
+ std::thread q(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock_shared();
+ for (auto& t : v)
+ t.join();
+ q.join();
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp
new file mode 100644
index 00000000000..9c4400555c3
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// shared_lock(mutex_type& m, adopt_lock_t);
+
+#include <shared_mutex>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_mutex m;
+ m.lock();
+ std::shared_lock<std::shared_mutex> lk(m, std::adopt_lock);
+ assert(lk.mutex() == &m);
+ assert(lk.owns_lock() == true);
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp
new file mode 100644
index 00000000000..2f2247a0ed2
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// shared_lock(mutex_type& m, defer_lock_t);
+
+#include <shared_mutex>
+#include <cassert>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_mutex m;
+ std::shared_lock<std::shared_mutex> lk(m, std::defer_lock);
+ assert(lk.mutex() == &m);
+ assert(lk.owns_lock() == false);
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp
new file mode 100644
index 00000000000..f3798af9c06
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class timed_mutex;
+
+// template <class Rep, class Period>
+// shared_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
+
+#include <shared_mutex>
+#include <thread>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ std::shared_lock<std::shared_mutex> lk(m, ms(300));
+ assert(lk.owns_lock() == true);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+void f2()
+{
+ time_point t0 = Clock::now();
+ std::shared_lock<std::shared_mutex> lk(m, ms(250));
+ assert(lk.owns_lock() == false);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f1));
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ }
+ {
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f2));
+ std::this_thread::sleep_for(ms(300));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp
new file mode 100644
index 00000000000..44eaee22ccd
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp
@@ -0,0 +1,79 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// template <class Clock, class Duration>
+// shared_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
+
+#include <shared_mutex>
+#include <thread>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ std::shared_lock<std::shared_mutex> lk(m, Clock::now() + ms(300));
+ assert(lk.owns_lock() == true);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ns(50000000)); // within 50ms
+}
+
+void f2()
+{
+ time_point t0 = Clock::now();
+ std::shared_lock<std::shared_mutex> lk(m, Clock::now() + ms(250));
+ assert(lk.owns_lock() == false);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f1));
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ }
+ {
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f2));
+ std::this_thread::sleep_for(ms(300));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp
new file mode 100644
index 00000000000..9dae3f96bda
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp
@@ -0,0 +1,72 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// shared_lock(mutex_type& m, try_to_lock_t);
+
+#include <shared_mutex>
+#include <thread>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f()
+{
+ time_point t0 = Clock::now();
+ {
+ std::shared_lock<std::shared_mutex> lk(m, std::try_to_lock);
+ assert(lk.owns_lock() == false);
+ }
+ {
+ std::shared_lock<std::shared_mutex> lk(m, std::try_to_lock);
+ assert(lk.owns_lock() == false);
+ }
+ {
+ std::shared_lock<std::shared_mutex> lk(m, std::try_to_lock);
+ assert(lk.owns_lock() == false);
+ }
+ while (true)
+ {
+ std::shared_lock<std::shared_mutex> lk(m, std::try_to_lock);
+ if (lk.owns_lock())
+ break;
+ }
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(200)); // within 200ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f));
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp
new file mode 100644
index 00000000000..c6617a51964
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp
@@ -0,0 +1,77 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// void lock();
+
+#include <shared_mutex>
+#include <thread>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f()
+{
+ std::shared_lock<std::shared_mutex> lk(m, std::defer_lock);
+ time_point t0 = Clock::now();
+ lk.lock();
+ time_point t1 = Clock::now();
+ assert(lk.owns_lock() == true);
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(25)); // within 25ms
+ try
+ {
+ lk.lock();
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EDEADLK);
+ }
+ lk.unlock();
+ lk.release();
+ try
+ {
+ lk.lock();
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EPERM);
+ }
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f));
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp
new file mode 100644
index 00000000000..d65fbfafe6a
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp
@@ -0,0 +1,68 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// bool try_lock();
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+bool try_lock_called = false;
+
+struct mutex
+{
+ bool try_lock_shared()
+ {
+ try_lock_called = !try_lock_called;
+ return try_lock_called;
+ }
+ void unlock_shared() {}
+};
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<mutex> lk(m, std::defer_lock);
+ assert(lk.try_lock() == true);
+ assert(try_lock_called == true);
+ assert(lk.owns_lock() == true);
+ try
+ {
+ lk.try_lock();
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EDEADLK);
+ }
+ lk.unlock();
+ assert(lk.try_lock() == false);
+ assert(try_lock_called == false);
+ assert(lk.owns_lock() == false);
+ lk.release();
+ try
+ {
+ lk.try_lock();
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EPERM);
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp
new file mode 100644
index 00000000000..d076e529630
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// template <class Rep, class Period>
+// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+bool try_lock_for_called = false;
+
+typedef std::chrono::milliseconds ms;
+
+struct mutex
+{
+ template <class Rep, class Period>
+ bool try_lock_shared_for(const std::chrono::duration<Rep, Period>& rel_time)
+ {
+ assert(rel_time == ms(5));
+ try_lock_for_called = !try_lock_for_called;
+ return try_lock_for_called;
+ }
+ void unlock_shared() {}
+};
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<mutex> lk(m, std::defer_lock);
+ assert(lk.try_lock_for(ms(5)) == true);
+ assert(try_lock_for_called == true);
+ assert(lk.owns_lock() == true);
+ try
+ {
+ lk.try_lock_for(ms(5));
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EDEADLK);
+ }
+ lk.unlock();
+ assert(lk.try_lock_for(ms(5)) == false);
+ assert(try_lock_for_called == false);
+ assert(lk.owns_lock() == false);
+ lk.release();
+ try
+ {
+ lk.try_lock_for(ms(5));
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EPERM);
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp
new file mode 100644
index 00000000000..8efffc46081
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// template <class Clock, class Duration>
+// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+bool try_lock_until_called = false;
+
+struct mutex
+{
+ template <class Clock, class Duration>
+ bool try_lock_shared_until(const std::chrono::time_point<Clock, Duration>& abs_time)
+ {
+ typedef std::chrono::milliseconds ms;
+ assert(Clock::now() - abs_time < ms(5));
+ try_lock_until_called = !try_lock_until_called;
+ return try_lock_until_called;
+ }
+ void unlock_shared() {}
+};
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ typedef std::chrono::steady_clock Clock;
+ std::shared_lock<mutex> lk(m, std::defer_lock);
+ assert(lk.try_lock_until(Clock::now()) == true);
+ assert(try_lock_until_called == true);
+ assert(lk.owns_lock() == true);
+ try
+ {
+ lk.try_lock_until(Clock::now());
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EDEADLK);
+ }
+ lk.unlock();
+ assert(lk.try_lock_until(Clock::now()) == false);
+ assert(try_lock_until_called == false);
+ assert(lk.owns_lock() == false);
+ lk.release();
+ try
+ {
+ lk.try_lock_until(Clock::now());
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EPERM);
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp
new file mode 100644
index 00000000000..9e4b3c8b9a1
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// void unlock();
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+bool unlock_called = false;
+
+struct mutex
+{
+ void lock_shared() {}
+ void unlock_shared() {unlock_called = true;}
+};
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<mutex> lk(m);
+ lk.unlock();
+ assert(unlock_called == true);
+ assert(lk.owns_lock() == false);
+ try
+ {
+ lk.unlock();
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EPERM);
+ }
+ lk.release();
+ try
+ {
+ lk.unlock();
+ assert(false);
+ }
+ catch (std::system_error& e)
+ {
+ assert(e.code().value() == EPERM);
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp
new file mode 100644
index 00000000000..6a7a39e9620
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// void swap(shared_lock& u) noexcept;
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+struct mutex
+{
+ void lock_shared() {}
+ void unlock_shared() {}
+};
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<mutex> lk1(m);
+ std::shared_lock<mutex> lk2;
+ lk1.swap(lk2);
+ assert(lk1.mutex() == nullptr);
+ assert(lk1.owns_lock() == false);
+ assert(lk2.mutex() == &m);
+ assert(lk2.owns_lock() == true);
+ static_assert(noexcept(lk1.swap(lk2)), "member swap must be noexcept");
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp
new file mode 100644
index 00000000000..03bf5e89bb7
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// template <class Mutex>
+// void swap(shared_lock<Mutex>& x, shared_lock<Mutex>& y) noexcept;
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+struct mutex
+{
+ void lock_shared() {}
+ void unlock_shared() {}
+};
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<mutex> lk1(m);
+ std::shared_lock<mutex> lk2;
+ swap(lk1, lk2);
+ assert(lk1.mutex() == nullptr);
+ assert(lk1.owns_lock() == false);
+ assert(lk2.mutex() == &m);
+ assert(lk2.owns_lock() == true);
+ static_assert(noexcept(swap(lk1, lk2)), "non-member swap must be noexcept");
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp
new file mode 100644
index 00000000000..a836b35dfa1
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp
@@ -0,0 +1,51 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// mutex_type* release() noexcept;
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+struct mutex
+{
+ static int lock_count;
+ static int unlock_count;
+ void lock_shared() {++lock_count;}
+ void unlock_shared() {++unlock_count;}
+};
+
+int mutex::lock_count = 0;
+int mutex::unlock_count = 0;
+
+mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<mutex> lk(m);
+ assert(lk.mutex() == &m);
+ assert(lk.owns_lock() == true);
+ assert(mutex::lock_count == 1);
+ assert(mutex::unlock_count == 0);
+ assert(lk.release() == &m);
+ assert(lk.mutex() == nullptr);
+ assert(lk.owns_lock() == false);
+ assert(mutex::lock_count == 1);
+ assert(mutex::unlock_count == 0);
+ static_assert(noexcept(lk.release()), "release must be noexcept");
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/mutex.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/mutex.pass.cpp
new file mode 100644
index 00000000000..927e9d1d48d
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/mutex.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// mutex_type *mutex() const noexcept;
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<std::shared_mutex> lk0;
+ assert(lk0.mutex() == nullptr);
+ std::shared_lock<std::shared_mutex> lk1(m);
+ assert(lk1.mutex() == &m);
+ lk1.unlock();
+ assert(lk1.mutex() == &m);
+ static_assert(noexcept(lk0.mutex()), "mutex() must be noexcept");
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/op_bool.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/op_bool.pass.cpp
new file mode 100644
index 00000000000..901ccbc1533
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/op_bool.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// explicit operator bool() const noexcept;
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<std::shared_mutex> lk0;
+ assert(static_cast<bool>(lk0) == false);
+ std::shared_lock<std::shared_mutex> lk1(m);
+ assert(static_cast<bool>(lk1) == true);
+ lk1.unlock();
+ assert(static_cast<bool>(lk1) == false);
+ static_assert(noexcept(static_cast<bool>(lk0)), "explicit operator bool() must be noexcept");
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/owns_lock.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/owns_lock.pass.cpp
new file mode 100644
index 00000000000..ca4715b67d1
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/owns_lock.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex> class shared_lock;
+
+// bool owns_lock() const noexcept;
+
+#include <shared_mutex>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_lock<std::shared_mutex> lk0;
+ assert(lk0.owns_lock() == false);
+ std::shared_lock<std::shared_mutex> lk1(m);
+ assert(lk1.owns_lock() == true);
+ lk1.unlock();
+ assert(lk1.owns_lock() == false);
+ static_assert(noexcept(lk0.owns_lock()), "owns_lock must be noexcept");
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/types.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/types.pass.cpp
new file mode 100644
index 00000000000..353735739b3
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.shared/types.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// template <class Mutex>
+// class shared_lock
+// {
+// public:
+// typedef Mutex mutex_type;
+// ...
+// };
+
+#include <shared_mutex>
+#include <type_traits>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ static_assert((std::is_same<std::shared_lock<std::mutex>::mutex_type,
+ std::mutex>::value), "");
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.mod/release.pass.cpp b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.mod/release.pass.cpp
index 0efe7d64de4..4252de15146 100644
--- a/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.mod/release.pass.cpp
+++ b/libcxx/test/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.mod/release.pass.cpp
@@ -11,7 +11,7 @@
// template <class Mutex> class unique_lock;
-// void swap(unique_lock& u);
+// mutex_type* release() noexcept;
#include <mutex>
#include <cassert>
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/nothing_to_do.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/nothing_to_do.pass.cpp
new file mode 100644
index 00000000000..b58f5c55b64
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/nothing_to_do.pass.cpp
@@ -0,0 +1,12 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int main()
+{
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/assign.fail.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/assign.fail.cpp
new file mode 100644
index 00000000000..1405a22c524
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/assign.fail.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// shared_mutex& operator=(const shared_mutex&) = delete;
+
+#include <shared_mutex>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_mutex m0;
+ std::shared_mutex m1;
+ m1 = m0;
+#else
+# error
+#endif
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/copy.fail.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/copy.fail.cpp
new file mode 100644
index 00000000000..7e699232ae7
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/copy.fail.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// shared_mutex(const shared_mutex&) = delete;
+
+#include <shared_mutex>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_mutex m0;
+ std::shared_mutex m1(m0);
+#else
+# error
+#endif
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/default.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/default.pass.cpp
new file mode 100644
index 00000000000..060fb924375
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/default.pass.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// shared_mutex();
+
+#include <shared_mutex>
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ std::shared_mutex m;
+#endif
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/lock.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/lock.pass.cpp
new file mode 100644
index 00000000000..2fd78008151
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/lock.pass.cpp
@@ -0,0 +1,52 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// void lock();
+
+#include <shared_mutex>
+#include <thread>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f()
+{
+ time_point t0 = Clock::now();
+ m.lock();
+ time_point t1 = Clock::now();
+ m.unlock();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/lock_shared.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/lock_shared.pass.cpp
new file mode 100644
index 00000000000..6fe1b446950
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/lock_shared.pass.cpp
@@ -0,0 +1,75 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// void lock_shared();
+
+#include <shared_mutex>
+#include <thread>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f()
+{
+ time_point t0 = Clock::now();
+ m.lock_shared();
+ time_point t1 = Clock::now();
+ m.unlock_shared();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+void g()
+{
+ time_point t0 = Clock::now();
+ m.lock_shared();
+ time_point t1 = Clock::now();
+ m.unlock_shared();
+ ns d = t1 - t0;
+ assert(d < ms(50)); // within 50ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f));
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ m.lock_shared();
+ for (auto& t : v)
+ t = std::thread(g);
+ std::thread q(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock_shared();
+ for (auto& t : v)
+ t.join();
+ q.join();
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock.pass.cpp
new file mode 100644
index 00000000000..86aa0c4e5c2
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock.pass.cpp
@@ -0,0 +1,56 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// bool try_lock();
+
+#include <shared_mutex>
+#include <thread>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f()
+{
+ time_point t0 = Clock::now();
+ assert(!m.try_lock());
+ assert(!m.try_lock());
+ assert(!m.try_lock());
+ while(!m.try_lock())
+ ;
+ time_point t1 = Clock::now();
+ m.unlock();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(200)); // within 200ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ m.lock();
+ std::thread t(f);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_for.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_for.pass.cpp
new file mode 100644
index 00000000000..1560359961f
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_for.pass.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// template <class Rep, class Period>
+// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
+
+#include <shared_mutex>
+#include <thread>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ assert(m.try_lock_for(ms(300)) == true);
+ time_point t1 = Clock::now();
+ m.unlock();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+void f2()
+{
+ time_point t0 = Clock::now();
+ assert(m.try_lock_for(ms(250)) == false);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ m.lock();
+ std::thread t(f1);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+ }
+ {
+ m.lock();
+ std::thread t(f2);
+ std::this_thread::sleep_for(ms(300));
+ m.unlock();
+ t.join();
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared.pass.cpp
new file mode 100644
index 00000000000..da859ab9974
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared.pass.cpp
@@ -0,0 +1,60 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// bool try_lock_shared();
+
+#include <shared_mutex>
+#include <thread>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::system_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f()
+{
+ time_point t0 = Clock::now();
+ assert(!m.try_lock_shared());
+ assert(!m.try_lock_shared());
+ assert(!m.try_lock_shared());
+ while(!m.try_lock_shared())
+ ;
+ time_point t1 = Clock::now();
+ m.unlock_shared();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(200)); // within 200ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f));
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared_for.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared_for.pass.cpp
new file mode 100644
index 00000000000..b1d6e4c6a52
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared_for.pass.cpp
@@ -0,0 +1,78 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// template <class Rep, class Period>
+// bool try_lock_shared_for(const chrono::duration<Rep, Period>& rel_time);
+
+#include <shared_mutex>
+#include <thread>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ assert(m.try_lock_shared_for(ms(300)) == true);
+ time_point t1 = Clock::now();
+ m.unlock_shared();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+void f2()
+{
+ time_point t0 = Clock::now();
+ assert(m.try_lock_shared_for(ms(250)) == false);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f1));
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ }
+ {
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f2));
+ std::this_thread::sleep_for(ms(300));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared_until.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared_until.pass.cpp
new file mode 100644
index 00000000000..3dbf0c7bd73
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_shared_until.pass.cpp
@@ -0,0 +1,78 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// template <class Clock, class Duration>
+// bool try_lock_shared_until(const chrono::time_point<Clock, Duration>& abs_time);
+
+#include <shared_mutex>
+#include <thread>
+#include <vector>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ assert(m.try_lock_shared_until(Clock::now() + ms(300)) == true);
+ time_point t1 = Clock::now();
+ m.unlock_shared();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+void f2()
+{
+ time_point t0 = Clock::now();
+ assert(m.try_lock_shared_until(Clock::now() + ms(250)) == false);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f1));
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ }
+ {
+ m.lock();
+ std::vector<std::thread> v;
+ for (int i = 0; i < 5; ++i)
+ v.push_back(std::thread(f2));
+ std::this_thread::sleep_for(ms(300));
+ m.unlock();
+ for (auto& t : v)
+ t.join();
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
diff --git a/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_until.pass.cpp b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_until.pass.cpp
new file mode 100644
index 00000000000..44f91f0afb5
--- /dev/null
+++ b/libcxx/test/thread/thread.mutex/thread.mutex.requirements/thread.sharedmutex.requirements/thread.sharedmutex.class/try_lock_until.pass.cpp
@@ -0,0 +1,71 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <shared_mutex>
+
+// class shared_mutex;
+
+// template <class Clock, class Duration>
+// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
+
+#include <shared_mutex>
+#include <thread>
+#include <cstdlib>
+#include <cassert>
+
+#if _LIBCPP_STD_VER > 11
+
+std::shared_mutex m;
+
+typedef std::chrono::steady_clock Clock;
+typedef Clock::time_point time_point;
+typedef Clock::duration duration;
+typedef std::chrono::milliseconds ms;
+typedef std::chrono::nanoseconds ns;
+
+void f1()
+{
+ time_point t0 = Clock::now();
+ assert(m.try_lock_until(Clock::now() + ms(300)) == true);
+ time_point t1 = Clock::now();
+ m.unlock();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+void f2()
+{
+ time_point t0 = Clock::now();
+ assert(m.try_lock_until(Clock::now() + ms(250)) == false);
+ time_point t1 = Clock::now();
+ ns d = t1 - t0 - ms(250);
+ assert(d < ms(50)); // within 50ms
+}
+
+#endif // _LIBCPP_STD_VER > 11
+
+int main()
+{
+#if _LIBCPP_STD_VER > 11
+ {
+ m.lock();
+ std::thread t(f1);
+ std::this_thread::sleep_for(ms(250));
+ m.unlock();
+ t.join();
+ }
+ {
+ m.lock();
+ std::thread t(f2);
+ std::this_thread::sleep_for(ms(300));
+ m.unlock();
+ t.join();
+ }
+#endif // _LIBCPP_STD_VER > 11
+}
OpenPOWER on IntegriCloud