summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/thread/thread.mutex
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2016-09-14 14:15:42 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2016-09-14 14:15:42 +0000
commitf239e6b7a28ff0ff29196710d460ab3fcf84a288 (patch)
tree5ace3ef64f1072cd61406634a7d7e3b2382876bb /libcxx/test/std/thread/thread.mutex
parenteec85de4c0b68be0b14a2f656ebb3cfca9b7b51a (diff)
downloadbcm5719-llvm-f239e6b7a28ff0ff29196710d460ab3fcf84a288.tar.gz
bcm5719-llvm-f239e6b7a28ff0ff29196710d460ab3fcf84a288.zip
[libcxx] Add a TSan regression test for a data race in call_once
Differential Revision: https://reviews.llvm.org/D24297 llvm-svn: 281477
Diffstat (limited to 'libcxx/test/std/thread/thread.mutex')
-rw-r--r--libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp b/libcxx/test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp
new file mode 100644
index 00000000000..33215819f58
--- /dev/null
+++ b/libcxx/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);
+}
OpenPOWER on IntegriCloud