diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 | 
| commit | b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d (patch) | |
| tree | 13f237c02db4d1894ab06884d1b739344766bede /test/std/thread/thread.mutex | |
| parent | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff) | |
Notes
Diffstat (limited to 'test/std/thread/thread.mutex')
40 files changed, 299 insertions, 206 deletions
diff --git a/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp index f67ca2169825..eac7600b5d11 100644 --- a/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock.algorithm/lock.pass.cpp @@ -7,6 +7,7 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads  // <mutex> diff --git a/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp index f0c54b71883f..8889408be2d7 100644 --- a/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock.algorithm/try_lock.pass.cpp @@ -7,6 +7,7 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads  // <mutex> diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp index 2c1c665fdeda..f7cf49c81f3f 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/default.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -20,9 +21,7 @@  int main()  { -#if _LIBCPP_STD_VER > 11      std::shared_lock<std::shared_timed_mutex> ul;      assert(!ul.owns_lock());      assert(ul.mutex() == nullptr); -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp index 8676f2ca0472..15c193c60b5d 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_assign.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -18,16 +19,11 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  std::shared_timed_mutex m0;  std::shared_timed_mutex m1; -#endif  // _LIBCPP_STD_VER > 11 -  int main()  { -#if _LIBCPP_STD_VER > 11      std::shared_lock<std::shared_timed_mutex> lk0(m0);      std::shared_lock<std::shared_timed_mutex> lk1(m1);      lk1 = std::move(lk0); @@ -35,5 +31,4 @@ int main()      assert(lk1.owns_lock() == true);      assert(lk0.mutex() == nullptr);      assert(lk0.owns_lock() == false); -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp index f59d2e826980..4f4f6a5e9fbd 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/move_ctor.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -18,18 +19,13 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -std::shared_timed_mutex m; -#endif  // _LIBCPP_STD_VER > 11 -  int main()  { -#if _LIBCPP_STD_VER > 11 +    std::shared_timed_mutex m;      std::shared_lock<std::shared_timed_mutex> lk0(m);      std::shared_lock<std::shared_timed_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/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp index c8a0287314bf..12bef34cf87b 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -21,9 +22,7 @@  #include <cstdlib>  #include <cassert> -#if _LIBCPP_STD_VER > 11 - -std::shared_timed_mutex m; +#include "test_macros.h"  typedef std::chrono::system_clock Clock;  typedef Clock::time_point time_point; @@ -31,6 +30,19 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif + +std::shared_timed_mutex m; +  void f()  {      time_point t0 = Clock::now(); @@ -39,8 +51,8 @@ void f()      std::shared_lock<std::shared_timed_mutex> ul(m);      t1 = Clock::now();      } -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance  }  void g() @@ -52,30 +64,30 @@ void g()      t1 = Clock::now();      }      ns d = t1 - t0; -    assert(d < ms(50));  // within 50ms +    assert(d < Tolerance);  // within tolerance  } -#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 +    { +        m.lock(); +        for (int i = 0; i < 5; ++i) +            v.push_back(std::thread(f)); +        std::this_thread::sleep_for(WaitTime); +        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(WaitTime); +        m.unlock_shared(); +        for (auto& t : v) +            t.join(); +        q.join(); +    }  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp index 3b49b3029052..995210221065 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_adopt_lock.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -20,11 +21,9 @@  int main()  { -#if _LIBCPP_STD_VER > 11      std::shared_timed_mutex m;      m.lock_shared();      std::shared_lock<std::shared_timed_mutex> lk(m, std::adopt_lock);      assert(lk.mutex() == &m);      assert(lk.owns_lock() == true); -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp index bbc38fcadb10..d81796b95bf3 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_defer_lock.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -20,10 +21,8 @@  int main()  { -#if _LIBCPP_STD_VER > 11      std::shared_timed_mutex m;      std::shared_lock<std::shared_timed_mutex> lk(m, std::defer_lock);      assert(lk.mutex() == &m);      assert(lk.owns_lock() == false); -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp index 9816e57f692a..84f868d6810b 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_duration.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -22,7 +23,7 @@  #include <cstdlib>  #include <cassert> -#if _LIBCPP_STD_VER > 11 +#include "test_macros.h"  std::shared_timed_mutex m; @@ -32,37 +33,46 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif + +  void f1()  {      time_point t0 = Clock::now(); -    std::shared_lock<std::shared_timed_mutex> lk(m, ms(300)); +    std::shared_lock<std::shared_timed_mutex> lk(m, WaitTime + Tolerance);      assert(lk.owns_lock() == true);      time_point t1 = Clock::now(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within 50ms  }  void f2()  {      time_point t0 = Clock::now(); -    std::shared_lock<std::shared_timed_mutex> lk(m, ms(250)); +    std::shared_lock<std::shared_timed_mutex> lk(m, WaitTime);      assert(lk.owns_lock() == false);      time_point t1 = Clock::now(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // 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)); +        std::this_thread::sleep_for(WaitTime);          m.unlock();          for (auto& t : v)              t.join(); @@ -72,10 +82,9 @@ int main()          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)); +        std::this_thread::sleep_for(WaitTime + Tolerance);          m.unlock();          for (auto& t : v)              t.join();      } -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp index 5d188ab06737..9359731486dd 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_time_point.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -22,7 +23,7 @@  #include <cstdlib>  #include <cassert> -#if _LIBCPP_STD_VER > 11 +#include "test_macros.h"  std::shared_timed_mutex m; @@ -32,37 +33,45 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif +  void f1()  {      time_point t0 = Clock::now(); -    std::shared_lock<std::shared_timed_mutex> lk(m, Clock::now() + ms(300)); +    std::shared_lock<std::shared_timed_mutex> lk(m, Clock::now() + WaitTime + Tolerance);      assert(lk.owns_lock() == true);      time_point t1 = Clock::now(); -    ns d = t1 - t0 - ms(250); -    assert(d < ns(50000000));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within 50ms  }  void f2()  {      time_point t0 = Clock::now(); -    std::shared_lock<std::shared_timed_mutex> lk(m, Clock::now() + ms(250)); +    std::shared_lock<std::shared_timed_mutex> lk(m, Clock::now() + WaitTime);      assert(lk.owns_lock() == false);      time_point t1 = Clock::now(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // 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)); +        std::this_thread::sleep_for(WaitTime);          m.unlock();          for (auto& t : v)              t.join(); @@ -72,10 +81,9 @@ int main()          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)); +        std::this_thread::sleep_for(WaitTime + Tolerance);          m.unlock();          for (auto& t : v)              t.join();      } -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp index f2d4e0deb73f..7f89f0af801f 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.cons/mutex_try_to_lock.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -21,8 +22,6 @@  #include <cstdlib>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  std::shared_timed_mutex m;  typedef std::chrono::system_clock Clock; @@ -57,11 +56,8 @@ void f()      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) @@ -70,5 +66,4 @@ int main()      m.unlock();      for (auto& t : v)          t.join(); -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp index f1500652badd..5c3513c98e03 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/lock.pass.cpp @@ -7,7 +7,9 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -21,7 +23,7 @@  #include <cstdlib>  #include <cassert> -#if _LIBCPP_STD_VER > 11 +#include "test_macros.h"  std::shared_timed_mutex m; @@ -31,6 +33,18 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(25); +#else +ms Tolerance = ms(25 * 5); +#endif + +  void f()  {      std::shared_lock<std::shared_timed_mutex> lk(m, std::defer_lock); @@ -38,8 +52,8 @@ void f()      lk.lock();      time_point t1 = Clock::now();      assert(lk.owns_lock() == true); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(25));  // within 25ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance      try      {          lk.lock(); @@ -62,18 +76,14 @@ void f()      }  } -#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)); +    std::this_thread::sleep_for(WaitTime);      m.unlock();      for (auto& t : v)          t.join(); -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp index 82b1ff865053..01693c77ea39 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock.pass.cpp @@ -7,7 +7,9 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -18,8 +20,6 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  bool try_lock_called = false;  struct mutex @@ -34,11 +34,9 @@ struct mutex  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); @@ -66,5 +64,4 @@ int main()      {          assert(e.code().value() == EPERM);      } -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp index 5867465a6626..852a94eb65ec 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_for.pass.cpp @@ -7,7 +7,9 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -19,8 +21,6 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  bool try_lock_for_called = false;  typedef std::chrono::milliseconds ms; @@ -39,11 +39,8 @@ struct mutex  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); @@ -71,5 +68,4 @@ int main()      {          assert(e.code().value() == EPERM);      } -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp index 9d38983be724..31574afd7d8f 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/try_lock_until.pass.cpp @@ -7,7 +7,9 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -19,8 +21,6 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  bool try_lock_until_called = false;  struct mutex @@ -38,11 +38,8 @@ struct mutex  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); @@ -71,5 +68,4 @@ int main()      {          assert(e.code().value() == EPERM);      } -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp index eb08a45cde6e..6a7385ed42a6 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.locking/unlock.pass.cpp @@ -7,7 +7,9 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -18,8 +20,6 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  bool unlock_called = false;  struct mutex @@ -30,11 +30,8 @@ struct mutex  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); @@ -58,5 +55,4 @@ int main()      {          assert(e.code().value() == EPERM);      } -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp index 8505763e44bc..23a0c7030d76 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/member_swap.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -18,8 +19,6 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  struct mutex  {      void lock_shared() {} @@ -28,11 +27,8 @@ struct mutex  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); @@ -41,5 +37,4 @@ int main()      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/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp index 057dbc4cd3b7..0f19174d51f0 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/nonmember_swap.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -19,8 +20,6 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  struct mutex  {      void lock_shared() {} @@ -29,11 +28,8 @@ struct mutex  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); @@ -42,5 +38,4 @@ int main()      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/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp index 65ddca624725..2b5f8c1f1658 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.mod/release.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -18,8 +19,6 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  struct mutex  {      static int lock_count; @@ -33,11 +32,8 @@ 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); @@ -49,5 +45,4 @@ int main()      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/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/mutex.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/mutex.pass.cpp index 4eb75d8f050e..711ab7c6fca0 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/mutex.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/mutex.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -18,15 +19,10 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  std::shared_timed_mutex m; -#endif  // _LIBCPP_STD_VER > 11 -  int main()  { -#if _LIBCPP_STD_VER > 11      std::shared_lock<std::shared_timed_mutex> lk0;      assert(lk0.mutex() == nullptr);      std::shared_lock<std::shared_timed_mutex> lk1(m); @@ -34,5 +30,4 @@ int main()      lk1.unlock();      assert(lk1.mutex() == &m);      static_assert(noexcept(lk0.mutex()), "mutex() must be noexcept"); -#endif  // _LIBCPP_STD_VER > 11  } diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/op_bool.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/op_bool.pass.cpp index d079d2d8b03a..3f6ad2b555a3 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/op_bool.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/op_bool.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -18,15 +19,10 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  std::shared_timed_mutex m; -#endif  // _LIBCPP_STD_VER > 11 -  int main()  { -#if _LIBCPP_STD_VER > 11      std::shared_lock<std::shared_timed_mutex> lk0;      assert(static_cast<bool>(lk0) == false);      std::shared_lock<std::shared_timed_mutex> lk1(m); @@ -34,5 +30,4 @@ int main()      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/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/owns_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/owns_lock.pass.cpp index d64b0aa6a736..5ab3ac009fe1 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/owns_lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/thread.lock.shared.obs/owns_lock.pass.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11  // <shared_mutex> @@ -18,15 +19,10 @@  #include <shared_mutex>  #include <cassert> -#if _LIBCPP_STD_VER > 11 -  std::shared_timed_mutex m; -#endif  // _LIBCPP_STD_VER > 11 -  int main()  { -#if _LIBCPP_STD_VER > 11      std::shared_lock<std::shared_timed_mutex> lk0;      assert(lk0.owns_lock() == false);      std::shared_lock<std::shared_timed_mutex> lk1(m); @@ -34,5 +30,4 @@ int main()      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/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/types.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/types.pass.cpp index c153b455f404..f555d3de5ee0 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/types.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.shared/types.pass.cpp @@ -8,6 +8,8 @@  //===----------------------------------------------------------------------===//  //  // UNSUPPORTED: libcpp-has-no-threads +// UNSUPPORTED: c++98, c++03, c++11 +  // <shared_mutex> @@ -24,8 +26,6 @@  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/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp index f5408df98199..6ce33761068f 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/lock.pass.cpp @@ -7,6 +7,7 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads  // <mutex> diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp index bd88577f0a22..27d0562de31f 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock.pass.cpp @@ -7,6 +7,7 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads  // <mutex> diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp index 558f079463a4..6f0a7219d2d8 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_for.pass.cpp @@ -7,6 +7,7 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads  // <mutex> diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp index 24e4d109a097..b7e87249b596 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/try_lock_until.pass.cpp @@ -7,6 +7,7 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads  // <mutex> diff --git a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp index bbabfc41df11..62497c9ec45a 100644 --- a/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp +++ b/test/std/thread/thread.mutex/thread.lock/thread.lock.unique/thread.lock.unique.locking/unlock.pass.cpp @@ -7,6 +7,7 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads  // <mutex> 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 index 7bcb2d61379a..5c67a34ab52b 100644 --- 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 @@ -6,6 +6,8 @@  // Source Licenses. See LICENSE.TXT for details.  //  //===----------------------------------------------------------------------===// +// +// UNSUPPORTED: c++98, c++03, c++11, c++14  // <shared_mutex> @@ -15,15 +17,9 @@  #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 +    m1 = m0; // expected-error {{overload resolution selected deleted operator '='}}  } 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 index af064aeee26c..c7cac6041c82 100644 --- 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 @@ -6,6 +6,8 @@  // Source Licenses. See LICENSE.TXT for details.  //  //===----------------------------------------------------------------------===// +// +// UNSUPPORTED: c++98, c++03, c++11, c++14  // <shared_mutex> @@ -15,14 +17,8 @@  #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 +    std::shared_mutex m1(m0); // expected-error {{call to deleted constructor of 'std::shared_mutex'}}  } 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 index 9bf7a79e3400..75ddebff0ed9 100644 --- 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 @@ -21,6 +21,7 @@  #include <cstdlib>  #include <cassert> +#include "test_macros.h"  std::shared_mutex m; @@ -30,21 +31,32 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif +  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 +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance  }  int main()  {      m.lock();      std::thread t(f); -    std::this_thread::sleep_for(ms(250)); +    std::this_thread::sleep_for(WaitTime);      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 index 3ffa9e2d0065..6b5089d38859 100644 --- 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 @@ -22,6 +22,8 @@  #include <cstdlib>  #include <cassert> +#include "test_macros.h" +  std::shared_mutex m;  typedef std::chrono::system_clock Clock; @@ -30,14 +32,25 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif +  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 +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance  }  void g() @@ -47,7 +60,7 @@ void g()      time_point t1 = Clock::now();      m.unlock_shared();      ns d = t1 - t0; -    assert(d < ms(50));  // within 50ms +    assert(d < Tolerance);  // within tolerance  } @@ -57,7 +70,7 @@ int main()      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)); +    std::this_thread::sleep_for(WaitTime);      m.unlock();      for (auto& t : v)          t.join(); @@ -65,7 +78,7 @@ int main()      for (auto& t : v)          t = std::thread(g);      std::thread q(f); -    std::this_thread::sleep_for(ms(250)); +    std::this_thread::sleep_for(WaitTime);      m.unlock_shared();      for (auto& t : v)          t.join(); 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 index 62bb736837ea..2818bd617542 100644 --- 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 @@ -21,6 +21,8 @@  #include <cstdlib>  #include <cassert> +#include "test_macros.h" +  std::shared_timed_mutex m;  typedef std::chrono::system_clock Clock; @@ -29,6 +31,19 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; + +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !TEST_HAS_FEATURE(thread_sanitizer) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(100); +#endif + +  void f()  {      time_point t0 = Clock::now(); 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 index 8fc6299f1b8f..77a9107de923 100644 --- 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 @@ -22,6 +22,8 @@  #include <cstdlib>  #include <cassert> +#include "test_macros.h" +  std::shared_timed_mutex m;  typedef std::chrono::system_clock Clock; @@ -30,14 +32,27 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; + +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif + +  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 +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance  }  void g() @@ -47,7 +62,7 @@ void g()      time_point t1 = Clock::now();      m.unlock_shared();      ns d = t1 - t0; -    assert(d < ms(50));  // within 50ms +    assert(d < Tolerance);  // within tolerance  } @@ -57,7 +72,7 @@ int main()      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)); +    std::this_thread::sleep_for(WaitTime);      m.unlock();      for (auto& t : v)          t.join(); @@ -65,7 +80,7 @@ int main()      for (auto& t : v)          t = std::thread(g);      std::thread q(f); -    std::this_thread::sleep_for(ms(250)); +    std::this_thread::sleep_for(WaitTime);      m.unlock_shared();      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_for.pass.cpp b/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/try_lock_for.pass.cpp index ab20241895ba..320a268ae77d 100644 --- 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 @@ -22,6 +22,8 @@  #include <cstdlib>  #include <cassert> +#include "test_macros.h" +  std::shared_timed_mutex m;  typedef std::chrono::steady_clock Clock; @@ -30,23 +32,35 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; + +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif +  void f1()  {      time_point t0 = Clock::now(); -    assert(m.try_lock_for(ms(300)) == true); +    assert(m.try_lock_for(WaitTime + Tolerance) == true);      time_point t1 = Clock::now();      m.unlock(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance  }  void f2()  {      time_point t0 = Clock::now(); -    assert(m.try_lock_for(ms(250)) == false); +    assert(m.try_lock_for(WaitTime) == false);      time_point t1 = Clock::now(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance  }  int main() @@ -54,14 +68,14 @@ int main()      {          m.lock();          std::thread t(f1); -        std::this_thread::sleep_for(ms(250)); +        std::this_thread::sleep_for(WaitTime);          m.unlock();          t.join();      }      {          m.lock();          std::thread t(f2); -        std::this_thread::sleep_for(ms(300)); +        std::this_thread::sleep_for(WaitTime + Tolerance);          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 index 9c2d8c9c8e5c..3d5604d886cb 100644 --- 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 @@ -22,6 +22,8 @@  #include <cstdlib>  #include <cassert> +#include "test_macros.h" +  std::shared_timed_mutex m;  typedef std::chrono::system_clock Clock; @@ -30,6 +32,13 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; + +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(200); +#else +ms Tolerance = ms(200 * 5); +#endif +  void f()  {      time_point t0 = Clock::now(); @@ -41,7 +50,7 @@ void f()      time_point t1 = Clock::now();      m.unlock_shared();      ns d = t1 - t0 - ms(250); -    assert(d < ms(200));  // within 200ms +    assert(d < Tolerance);  // within tolerance  }  int main() 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 index 35444112a5da..4cdb5873f9a1 100644 --- 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 @@ -23,6 +23,8 @@  #include <cstdlib>  #include <cassert> +#include "test_macros.h" +  std::shared_timed_mutex m;  typedef std::chrono::steady_clock Clock; @@ -31,23 +33,34 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif +  void f1()  {      time_point t0 = Clock::now(); -    assert(m.try_lock_shared_for(ms(300)) == true); +    assert(m.try_lock_shared_for(WaitTime + Tolerance) == true);      time_point t1 = Clock::now();      m.unlock_shared(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within 50ms  }  void f2()  {      time_point t0 = Clock::now(); -    assert(m.try_lock_shared_for(ms(250)) == false); +    assert(m.try_lock_shared_for(WaitTime) == false);      time_point t1 = Clock::now(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within 50ms  }  int main() @@ -57,7 +70,7 @@ int main()          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)); +        std::this_thread::sleep_for(WaitTime);          m.unlock();          for (auto& t : v)              t.join(); @@ -67,7 +80,7 @@ int main()          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)); +        std::this_thread::sleep_for(WaitTime + Tolerance);          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 index 4e0f19de07ce..f7ddbaeef498 100644 --- 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 @@ -23,6 +23,8 @@  #include <cstdlib>  #include <cassert> +#include "test_macros.h" +  std::shared_timed_mutex m;  typedef std::chrono::steady_clock Clock; @@ -31,23 +33,34 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif +  void f1()  {      time_point t0 = Clock::now(); -    assert(m.try_lock_shared_until(Clock::now() + ms(300)) == true); +    assert(m.try_lock_shared_until(Clock::now() + WaitTime + Tolerance) == true);      time_point t1 = Clock::now();      m.unlock_shared(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within 50ms  }  void f2()  {      time_point t0 = Clock::now(); -    assert(m.try_lock_shared_until(Clock::now() + ms(250)) == false); +    assert(m.try_lock_shared_until(Clock::now() + WaitTime) == false);      time_point t1 = Clock::now(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance  }  int main() @@ -57,7 +70,7 @@ int main()          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)); +        std::this_thread::sleep_for(WaitTime);          m.unlock();          for (auto& t : v)              t.join(); @@ -67,7 +80,7 @@ int main()          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)); +        std::this_thread::sleep_for(WaitTime + Tolerance);          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 index aa90cf71502f..1560af2c9ecc 100644 --- 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 @@ -32,23 +32,35 @@ typedef Clock::duration duration;  typedef std::chrono::milliseconds ms;  typedef std::chrono::nanoseconds ns; + +ms WaitTime = ms(250); + +// Thread sanitizer causes more overhead and will sometimes cause this test +// to fail. To prevent this we give Thread sanitizer more time to complete the +// test. +#if !defined(TEST_HAS_SANITIZERS) +ms Tolerance = ms(50); +#else +ms Tolerance = ms(50 * 5); +#endif +  void f1()  {      time_point t0 = Clock::now(); -    assert(m.try_lock_until(Clock::now() + ms(300)) == true); +    assert(m.try_lock_until(Clock::now() + WaitTime + Tolerance) == true);      time_point t1 = Clock::now();      m.unlock(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance  }  void f2()  {      time_point t0 = Clock::now(); -    assert(m.try_lock_until(Clock::now() + ms(250)) == false); +    assert(m.try_lock_until(Clock::now() + WaitTime) == false);      time_point t1 = Clock::now(); -    ns d = t1 - t0 - ms(250); -    assert(d < ms(50));  // within 50ms +    ns d = t1 - t0 - WaitTime; +    assert(d < Tolerance);  // within tolerance  }  int main() @@ -56,14 +68,14 @@ int main()      {          m.lock();          std::thread t(f1); -        std::this_thread::sleep_for(ms(250)); +        std::this_thread::sleep_for(WaitTime);          m.unlock();          t.join();      }      {          m.lock();          std::thread t(f2); -        std::this_thread::sleep_for(ms(300)); +        std::this_thread::sleep_for(WaitTime + Tolerance);          m.unlock();          t.join();      } diff --git a/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp b/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp index 89b99348459b..afc318cc3d7a 100644 --- a/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp +++ b/test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp @@ -7,6 +7,7 @@  //  //===----------------------------------------------------------------------===//  // +// XFAIL: libcpp-no-exceptions  // UNSUPPORTED: libcpp-has-no-threads  // <mutex>  | 
