File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
test/std/thread/futures/futures.async Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -1829,7 +1829,16 @@ template <class _Rp, class _Fp>
1829
1829
_LIBCPP_HIDE_FROM_ABI future<_Rp> __make_async_assoc_state (_Fp&& __f) {
1830
1830
unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count> __h (
1831
1831
new __async_assoc_state<_Rp, _Fp>(std::forward<_Fp>(__f)));
1832
- std::thread (&__async_assoc_state<_Rp, _Fp>::__execute, __h.get ()).detach ();
1832
+ #if _LIBCPP_HAS_EXCEPTIONS
1833
+ try {
1834
+ #endif
1835
+ std::thread (&__async_assoc_state<_Rp, _Fp>::__execute, __h.get ()).detach ();
1836
+ #if _LIBCPP_HAS_EXCEPTIONS
1837
+ } catch (...) {
1838
+ __h->__make_ready ();
1839
+ throw ;
1840
+ }
1841
+ #endif
1833
1842
return future<_Rp>(__h.get ());
1834
1843
}
1835
1844
Original file line number Diff line number Diff line change
1
+ // ===----------------------------------------------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+ //
9
+ // UNSUPPORTED: no-threads
10
+ // UNSUPPORTED: c++03
11
+
12
+ // This test uses std::atomic interfaces that are only available in C++20
13
+ // UNSUPPORTED: c++11, c++14, c++17
14
+
15
+ // Make sure that the `future` destructor keeps the data alive until the thread finished. This test fails by triggering
16
+ // TSan. It may not be observable by normal means.
17
+
18
+ #include < atomic>
19
+ #include < future>
20
+ #include < mutex>
21
+
22
+ std::mutex mux;
23
+
24
+ int main () {
25
+ using namespace std ::chrono_literals;
26
+ std::scoped_lock lock (mux);
27
+ std::atomic<bool > in_async = false ;
28
+ auto v = std::async (std::launch::async, [&in_async, value = 1 ]() mutable {
29
+ in_async = true ;
30
+ in_async.notify_all ();
31
+ std::scoped_lock thread_lock (mux);
32
+ value = 4 ;
33
+ (void )value;
34
+ });
35
+ in_async.wait (true );
36
+ }
You can’t perform that action at this time.
0 commit comments