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
21 #include <system_error>
24 #include "make_test_thread.h"
25 #include "test_macros.h"
27 std::atomic_bool
done(false);
36 G() : alive_(1) {++n_alive
;}
37 G(const G
& g
) : alive_(g
.alive_
) {++n_alive
;}
38 ~G() {alive_
= 0; --n_alive
;}
49 bool G::op_run
= false;
51 void foo() { done
= true; }
57 std::thread t0
= support::make_test_thread(g
);
58 assert(t0
.joinable());
60 assert(!t0
.joinable());
61 #ifndef TEST_HAS_NO_EXCEPTIONS
65 } catch (std::system_error
const&) {
69 #ifndef TEST_HAS_NO_EXCEPTIONS
71 std::thread t0
= support::make_test_thread(foo
);
76 } catch (std::system_error
const&) {
78 // Wait to make sure that the detached thread has started up.
79 // Without this, we could exit main and start destructing global
80 // resources that are needed when the thread starts up, while the
81 // detached thread would start up only later.