summaryrefslogtreecommitdiff
path: root/test/std/thread/thread.mutex/thread.once/thread.once.callonce
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/thread/thread.mutex/thread.once/thread.once.callonce')
-rw-r--r--test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp7
-rw-r--r--test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp48
2 files changed, 53 insertions, 2 deletions
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 71b054fced88..138b657196da 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,7 +7,6 @@
//
//===----------------------------------------------------------------------===//
//
-// XFAIL: libcpp-no-exceptions
// UNSUPPORTED: libcpp-has-no-threads
// <mutex>
@@ -50,12 +49,13 @@ void init3()
++init3_called;
std::this_thread::sleep_for(ms(250));
if (init3_called == 1)
- throw 1;
+ TEST_THROW(1);
++init3_completed;
}
void f3()
{
+#ifndef TEST_HAS_NO_EXCEPTIONS
try
{
std::call_once(flg3, init3);
@@ -63,6 +63,7 @@ void f3()
catch (...)
{
}
+#endif
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
@@ -197,6 +198,7 @@ int main()
t1.join();
assert(init0_called == 1);
}
+#ifndef TEST_HAS_NO_EXCEPTIONS
// check basic exception safety
{
std::thread t0(f3);
@@ -206,6 +208,7 @@ int main()
assert(init3_called == 2);
assert(init3_completed == 1);
}
+#endif
// check deadlock avoidance
{
std::thread t0(f41);
diff --git a/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp b/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp
new file mode 100644
index 000000000000..33215819f585
--- /dev/null
+++ b/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+// struct once_flag;
+
+// template<class Callable, class ...Args>
+// void call_once(once_flag& flag, Callable&& func, Args&&... args);
+
+// This test is supposed to be run with ThreadSanitizer and verifies that
+// call_once properly synchronizes user state, a data race that was fixed
+// in r280621.
+
+#include <mutex>
+#include <thread>
+#include <cassert>
+
+std::once_flag flg0;
+long global = 0;
+
+void init0()
+{
+ ++global;
+}
+
+void f0()
+{
+ std::call_once(flg0, init0);
+ assert(global == 1);
+}
+
+int main()
+{
+ std::thread t0(f0);
+ std::thread t1(f0);
+ t0.join();
+ t1.join();
+ assert(global == 1);
+}