diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:18:58 +0000 |
| commit | 53a420fba21cf1644972b34dcd811a43cdb8368d (patch) | |
| tree | 66a19f6f8b65215772549a51d688492ab8addc0d /test/std/thread/thread.mutex/thread.once/thread.once.callonce | |
| parent | b50f1549701eb950921e5d6f2e55ba1a1dadbb43 (diff) | |
Notes
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.cpp | 7 | ||||
| -rw-r--r-- | test/std/thread/thread.mutex/thread.once/thread.once.callonce/race.pass.cpp | 48 |
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); +} |
