[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / test / std / thread / thread.threads / thread.thread.class / thread.thread.member / join.pass.cpp
blob509d0197c0332bef218d6d7aaab6aa03e8057556
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
11 // <thread>
13 // class thread
15 // void join();
17 #include <thread>
18 #include <new>
19 #include <cstdlib>
20 #include <cassert>
21 #include <system_error>
22 #include <atomic>
24 #include "make_test_thread.h"
25 #include "test_macros.h"
27 std::atomic_bool done(false);
29 class G
31 int alive_;
32 public:
33 static int n_alive;
34 static bool op_run;
36 G() : alive_(1) {++n_alive;}
37 G(const G& g) : alive_(g.alive_) {++n_alive;}
38 ~G() {alive_ = 0; --n_alive;}
40 void operator()()
42 assert(alive_ == 1);
43 assert(n_alive >= 1);
44 op_run = true;
48 int G::n_alive = 0;
49 bool G::op_run = false;
51 void foo() { done = true; }
53 int main(int, char**)
56 G g;
57 std::thread t0 = support::make_test_thread(g);
58 assert(t0.joinable());
59 t0.join();
60 assert(!t0.joinable());
61 #ifndef TEST_HAS_NO_EXCEPTIONS
62 try {
63 t0.join();
64 assert(false);
65 } catch (std::system_error const&) {
67 #endif
69 #ifndef TEST_HAS_NO_EXCEPTIONS
71 std::thread t0 = support::make_test_thread(foo);
72 t0.detach();
73 try {
74 t0.join();
75 assert(false);
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.
82 while (!done) {}
84 #endif
86 return 0;