File tree Expand file tree Collapse file tree 2 files changed +50
-2
lines changed
test/std/thread/futures/futures.async Expand file tree Collapse file tree 2 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -865,7 +865,8 @@ void __async_assoc_state<_Rp, _Fp>::__execute() {
865865
866866template <class _Rp , class _Fp >
867867void __async_assoc_state<_Rp, _Fp>::__on_zero_shared () _NOEXCEPT {
868- this ->wait ();
868+ if (base::__state_ & base::__constructed)
869+ this ->wait ();
869870 base::__on_zero_shared ();
870871}
871872
@@ -902,7 +903,8 @@ void __async_assoc_state<void, _Fp>::__execute() {
902903
903904template <class _Fp >
904905void __async_assoc_state<void , _Fp>::__on_zero_shared () _NOEXCEPT {
905- this ->wait ();
906+ if (base::__state_ & base::__constructed)
907+ this ->wait ();
906908 base::__on_zero_shared ();
907909}
908910
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+
11+ // There is no way to limit the number of threads on windows
12+ // UNSUPPORTED: msvc
13+
14+ #include < cassert>
15+ #include < future>
16+ #include < system_error>
17+
18+ #if __has_include(<sys/resource.h>)
19+ # include < sys/resource.h>
20+ # ifdef RLIMIT_NPROC
21+ void force_thread_creation_failure () {
22+ rlimit lim = {1 , 1 };
23+ setrlimit (RLIMIT_NPROC, &lim);
24+ }
25+ # else
26+ # error "No known way to force only one thread being available"
27+ # endif
28+ #else
29+ # error "No known way to force only one thread being available"
30+ #endif
31+
32+ int main () {
33+ force_thread_creation_failure ();
34+
35+ try {
36+ auto fut = std::async (std::launch::async, [] { return 1 ; });
37+ assert (false );
38+ } catch (const std::system_error&) {
39+ }
40+
41+ try {
42+ auto fut = std::async (std::launch::async, [] { return ; });
43+ assert (false );
44+ } catch (const std::system_error&) {
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments