diff options
Diffstat (limited to 'test/std/thread/thread.mutex/thread.mutex.requirements')
51 files changed, 2068 insertions, 0 deletions
diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/nothing_to_do.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.general/nothing_to_do.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.general/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.general/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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/nothing_to_do.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/assign.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/assign.fail.cpp new file mode 100644 index 000000000000..7f6333af9e29 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/assign.fail.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. +// +//===----------------------------------------------------------------------===// + +// <mutex> + +// class mutex; + +// mutex& operator=(const mutex&) = delete; + +#include <mutex> + +int main() +{ + std::mutex m0; + std::mutex m1; + m1 = m0; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/copy.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/copy.fail.cpp new file mode 100644 index 000000000000..7e1a07ac8c1a --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/copy.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <mutex> + +// class mutex; + +// mutex(const mutex&) = delete; + +#include <mutex> + +int main() +{ + std::mutex m0; + std::mutex m1(m0); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/default.pass.cpp new file mode 100644 index 000000000000..4de42fbd0243 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class mutex; + +// mutex(); + +#include <mutex> + +int main() +{ + std::mutex m; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/lock.pass.cpp new file mode 100644 index 000000000000..ba2d54d58663 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/lock.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class mutex; + +// void lock(); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +#include <iostream> + +std::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 +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.pass.cpp new file mode 100644 index 000000000000..12c80f02c340 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/native_handle.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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class mutex; + +// typedef pthread_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include <mutex> +#include <cassert> + +int main() +{ + std::mutex m; + pthread_mutex_t* h = m.native_handle(); + assert(h); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/try_lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/try_lock.pass.cpp new file mode 100644 index 000000000000..fe8f351d7db7 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.class/try_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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class mutex; + +// bool try_lock(); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::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 +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/assign.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/assign.fail.cpp new file mode 100644 index 000000000000..61b56216e8fb --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/assign.fail.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. +// +//===----------------------------------------------------------------------===// + +// <mutex> + +// class recursive_mutex; + +// recursive_mutex& operator=(const recursive_mutex&) = delete; + +#include <mutex> + +int main() +{ + std::recursive_mutex m0; + std::recursive_mutex m1; + m1 = m0; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/copy.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/copy.fail.cpp new file mode 100644 index 000000000000..0239c0475ac2 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/copy.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <mutex> + +// class recursive_mutex; + +// recursive_mutex(const recursive_mutex&) = delete; + +#include <mutex> + +int main() +{ + std::recursive_mutex m0; + std::recursive_mutex m1(m0); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/default.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/default.pass.cpp new file mode 100644 index 000000000000..8c5d26675d3f --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_mutex; + +// recursive_mutex(); + +#include <mutex> + +int main() +{ + std::recursive_mutex m; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/lock.pass.cpp new file mode 100644 index 000000000000..abebe906378c --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_mutex; + +// void lock(); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +#include <iostream> + +std::recursive_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.lock(); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + assert(d < ms(200)); // within 200ms +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.pass.cpp new file mode 100644 index 000000000000..10626bc4072e --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/native_handle.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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_mutex; + +// typedef pthread_mutex_t* native_handle_type; +// native_handle_type native_handle(); + +#include <mutex> +#include <cassert> + +int main() +{ + std::recursive_mutex m; + pthread_mutex_t* h = m.native_handle(); + assert(h); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/try_lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/try_lock.pass.cpp new file mode 100644 index 000000000000..ff546d4ad66d --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.mutex.requirements.mutex/thread.mutex.recursive/try_lock.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_mutex; + +// bool try_lock(); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::recursive_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(); + assert(m.try_lock()); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + assert(d < ms(200)); // within 200ms +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/nothing_to_do.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.cpp new file mode 100644 index 000000000000..7bcb2d61379a --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/assign.fail.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> + +// class shared_mutex; + +// shared_mutex& operator=(const shared_mutex&) = delete; + +#include <shared_mutex> + +#include "test_macros.h" + +int main() +{ +#if TEST_STD_VER > 14 + std::shared_mutex m0; + std::shared_mutex m1; + m1 = m0; +#else +# error +#endif +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.cpp new file mode 100644 index 000000000000..af064aeee26c --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/copy.fail.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> + +// class shared_mutex; + +// shared_mutex(const shared_mutex&) = delete; + +#include <shared_mutex> + +#include "test_macros.h" + +int main() +{ +#if TEST_STD_VER > 14 + std::shared_mutex m0; + std::shared_mutex m1(m0); +#else +# error +#endif +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp new file mode 100644 index 000000000000..c61a93aa0c7f --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/default.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11, c++14 + +// <shared_mutex> + +// class shared_mutex; + +// shared_mutex(); + +#include <shared_mutex> + +int main() +{ + std::shared_mutex m; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp new file mode 100644 index 000000000000..9bf7a79e3400 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11, c++14 + +// <shared_mutex> + +// class shared_mutex; + +// void lock(); + +#include <shared_mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + + +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 +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.pass.cpp new file mode 100644 index 000000000000..3ffa9e2d0065 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/lock_shared.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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11, c++14 + +// <shared_mutex> + +// class shared_mutex; + +// void lock_shared(); + +#include <shared_mutex> +#include <thread> +#include <vector> +#include <cstdlib> +#include <cassert> + +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 +} + + +int main() +{ + 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(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock.pass.cpp new file mode 100644 index 000000000000..6f3ca24a4558 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11, c++14 + +// <shared_mutex> + +// class shared_mutex; + +// bool try_lock(); + +#include <shared_mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +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 +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock_shared.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock_shared.pass.cpp new file mode 100644 index 000000000000..52007155ba5f --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.shared_mutex.requirements/thread.shared_mutex.class/try_lock_shared.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11, c++14 + +// <shared_mutex> + +// class shared_mutex; + +// bool try_lock_shared(); + +#include <shared_mutex> +#include <thread> +#include <vector> +#include <cstdlib> +#include <cassert> + +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 +} + + +int main() +{ + 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(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/nothing_to_do.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/assign.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/assign.fail.cpp new file mode 100644 index 000000000000..528aaca6d9e1 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.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_timed_mutex; + +// shared_timed_mutex& operator=(const shared_timed_mutex&) = delete; + +#include <shared_mutex> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::shared_timed_mutex m0; + std::shared_timed_mutex m1; + m1 = m0; +#else +# error +#endif +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/copy.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/copy.fail.cpp new file mode 100644 index 000000000000..dbf01002e691 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.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_timed_mutex; + +// shared_timed_mutex(const shared_timed_mutex&) = delete; + +#include <shared_mutex> + +int main() +{ +#if _LIBCPP_STD_VER > 11 + std::shared_timed_mutex m0; + std::shared_timed_mutex m1(m0); +#else +# error +#endif +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/default.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/default.pass.cpp new file mode 100644 index 000000000000..45cd563f9407 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/default.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_mutex; + +// shared_timed_mutex(); + +#include <shared_mutex> + +int main() +{ + std::shared_timed_mutex m; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp new file mode 100644 index 000000000000..62bb736837ea --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_mutex; + +// void lock(); + +#include <shared_mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::shared_timed_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 +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp new file mode 100644 index 000000000000..8fc6299f1b8f --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_mutex; + +// void lock_shared(); + +#include <shared_mutex> +#include <thread> +#include <vector> +#include <cstdlib> +#include <cassert> + +std::shared_timed_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 +} + + +int main() +{ + 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(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock.pass.cpp new file mode 100644 index 000000000000..61900ba83342 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_mutex; + +// bool try_lock(); + +#include <shared_mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::shared_timed_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 +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp new file mode 100644 index 000000000000..ab20241895ba --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_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> + +std::shared_timed_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 +} + +int main() +{ + { + 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(); + } +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp new file mode 100644 index 000000000000..9c2d8c9c8e5c --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_mutex; + +// bool try_lock_shared(); + +#include <shared_mutex> +#include <thread> +#include <vector> +#include <cstdlib> +#include <cassert> + +std::shared_timed_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 +} + +int main() +{ + 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(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.pass.cpp new file mode 100644 index 000000000000..35444112a5da --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_for.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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_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> + +std::shared_timed_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 +} + +int main() +{ + { + 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(); + } +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.pass.cpp new file mode 100644 index 000000000000..4e0f19de07ce --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_shared_until.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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_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> + +std::shared_timed_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 +} + +int main() +{ + { + 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(); + } +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp new file mode 100644 index 000000000000..aa90cf71502f --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_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> + +#include "test_macros.h" + +std::shared_timed_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 +} + +int main() +{ + { + 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(); + } +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp new file mode 100644 index 000000000000..ed288099c979 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_until_deadlock_bug.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++03, c++98, c++11 + +// <shared_mutex> + +// class shared_timed_mutex; + +#include <shared_mutex> + +#include <atomic> +#include <chrono> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::shared_timed_mutex m; + +const int total_readers = 2; +std::atomic<int> readers_started(0); +std::atomic<int> readers_finished(0); + +// Wait for the readers to start then try and acquire the write lock. +void writer_one() { + while (readers_started != total_readers) {} + bool b = m.try_lock_for(std::chrono::milliseconds(500)); + assert(b == false); +} + +void blocked_reader() { + ++readers_started; + // Wait until writer_one is waiting for the write lock. + while (m.try_lock_shared()) { + m.unlock_shared(); + } + // Attempt to get the read lock. writer_one should be blocking us because + // writer_one is blocked by main. + m.lock_shared(); + ++readers_finished; + m.unlock_shared(); +} + +int main() +{ + typedef std::chrono::steady_clock Clock; + + m.lock_shared(); + std::thread t1(writer_one); + // create some readers + std::thread t2(blocked_reader); + std::thread t3(blocked_reader); + // Kill the test after 10 seconds if it hasn't completed. + auto end_point = Clock::now() + std::chrono::seconds(10); + while (readers_finished != total_readers && Clock::now() < end_point) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + assert(readers_finished == total_readers); + m.unlock_shared(); + t1.join(); + t2.join(); + t3.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/nothing_to_do.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/nothing_to_do.pass.cpp new file mode 100644 index 000000000000..b58f5c55b643 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.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/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/assign.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/assign.fail.cpp new file mode 100644 index 000000000000..58006833ecac --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/assign.fail.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. +// +//===----------------------------------------------------------------------===// + +// <mutex> + +// class timed_mutex; + +// timed_mutex& operator=(const timed_mutex&) = delete; + +#include <mutex> + +int main() +{ + std::timed_mutex m0; + std::timed_mutex m1; + m1 = m0; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/copy.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/copy.fail.cpp new file mode 100644 index 000000000000..61ba31d8648e --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/copy.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <mutex> + +// class timed_mutex; + +// timed_mutex(const timed_mutex&) = delete; + +#include <mutex> + +int main() +{ + std::timed_mutex m0; + std::timed_mutex m1(m0); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/default.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/default.pass.cpp new file mode 100644 index 000000000000..33320a7e260a --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class timed_mutex; + +// timed_mutex(); + +#include <mutex> + +int main() +{ + std::timed_mutex m; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/lock.pass.cpp new file mode 100644 index 000000000000..fe2dd825c207 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/lock.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class timed_mutex; + +// void lock(); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +#include <iostream> + +std::timed_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 +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock.pass.cpp new file mode 100644 index 000000000000..b32a2664551a --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class timed_mutex; + +// bool try_lock(); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::timed_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 +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_for.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_for.pass.cpp new file mode 100644 index 000000000000..46222a70c8d9 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_for.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class timed_mutex; + +// template <class Rep, class Period> +// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::timed_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 +} + +int main() +{ + { + 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(); + } +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_until.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_until.pass.cpp new file mode 100644 index 000000000000..6c9c442ab124 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.class/try_lock_until.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class timed_mutex; + +// template <class Clock, class Duration> +// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::timed_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 +} + +int main() +{ + { + 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(); + } +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/assign.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/assign.fail.cpp new file mode 100644 index 000000000000..ae84be838d66 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/assign.fail.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. +// +//===----------------------------------------------------------------------===// + +// <mutex> + +// class recursive_timed_mutex; + +// recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete; + +#include <mutex> + +int main() +{ + std::recursive_timed_mutex m0; + std::recursive_timed_mutex m1; + m1 = m0; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/copy.fail.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/copy.fail.cpp new file mode 100644 index 000000000000..487d6a8c269c --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/copy.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <mutex> + +// class recursive_timed_mutex; + +// recursive_timed_mutex(const recursive_timed_mutex&) = delete; + +#include <mutex> + +int main() +{ + std::recursive_timed_mutex m0; + std::recursive_timed_mutex m1(m0); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/default.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/default.pass.cpp new file mode 100644 index 000000000000..56e1874dc126 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_timed_mutex; + +// recursive_timed_mutex(); + +#include <mutex> + +int main() +{ + std::recursive_timed_mutex m; +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/lock.pass.cpp new file mode 100644 index 000000000000..91f747bc1ab0 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_timed_mutex; + +// void lock(); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +#include <iostream> + +std::recursive_timed_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.lock(); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + assert(d < ms(50)); // within 50ms +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock.pass.cpp new file mode 100644 index 000000000000..63c3cfee38a3 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_timed_mutex; + +// bool try_lock(); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::recursive_timed_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(); + assert(m.try_lock()); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + assert(d < ms(200)); // within 200ms +} + +int main() +{ + m.lock(); + std::thread t(f); + std::this_thread::sleep_for(ms(250)); + m.unlock(); + t.join(); +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_for.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_for.pass.cpp new file mode 100644 index 000000000000..3c1d6ddc6f40 --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_for.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_timed_mutex; + +// template <class Rep, class Period> +// bool try_lock_for(const chrono::duration<Rep, Period>& rel_time); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::recursive_timed_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(); + assert(m.try_lock()); + m.unlock(); + m.unlock(); + ns d = t1 - t0 - ms(250); + assert(d < ns(50000000)); // 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 < ns(50000000)); // within 50ms +} + +int main() +{ + { + 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(); + } +} diff --git a/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_until.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_until.pass.cpp new file mode 100644 index 000000000000..066eb7b3064c --- /dev/null +++ b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.timedmutex.requirements/thread.timedmutex.recursive/try_lock_until.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: libcpp-has-no-threads + +// <mutex> + +// class recursive_timed_mutex; + +// template <class Clock, class Duration> +// bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time); + +#include <mutex> +#include <thread> +#include <cstdlib> +#include <cassert> + +std::recursive_timed_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(); + assert(m.try_lock()); + m.unlock(); + 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 +} + +int main() +{ + { + 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(); + } +} |