1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
19 #include <system_error>
22 #include "make_test_thread.h"
23 #include "test_macros.h"
25 std::atomic_bool
done(false);
35 G() : alive_(1), done_(false)
40 G(const G
& g
) : alive_(g
.alive_
), done_(false)
48 if (done_
) done
= true;
61 bool G::op_run
= false;
63 void foo() { done
= true; }
69 std::thread t0
= support::make_test_thread(g
);
70 assert(t0
.joinable());
72 assert(!t0
.joinable());
75 assert(G::n_alive
== 1);
77 assert(G::n_alive
== 0);
79 #ifndef TEST_HAS_NO_EXCEPTIONS
81 std::thread t0
= support::make_test_thread(foo
);
82 assert(t0
.joinable());
84 assert(!t0
.joinable());
87 } catch (std::system_error
const&) {
89 // Wait to make sure that the detached thread has started up.
90 // Without this, we could exit main and start destructing global
91 // resources that are needed when the thread starts up, while the
92 // detached thread would start up only later.