aboutsummaryrefslogtreecommitdiff
path: root/test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp')
-rw-r--r--test/std/thread/thread.mutex/thread.mutex.requirements/thread.sharedtimedmutex.requirements/thread.sharedtimedmutex.class/lock_shared.pass.cpp25
1 files changed, 20 insertions, 5 deletions
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();