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: libcpp-has-no-threads, libcpp-has-thread-api-external 10 11 // XFAIL: windows 12 13 // <thread> 14 15 // class thread 16 17 // native_handle_type native_handle(); 18 19 #include <thread> 20 #include <new> 21 #include <cstdlib> 22 #include <cassert> 23 24 #include "test_macros.h" 25 26 class G 27 { 28 int alive_; 29 public: 30 static int n_alive; 31 static bool op_run; 32 G()33 G() : alive_(1) {++n_alive;} G(const G & g)34 G(const G& g) : alive_(g.alive_) {++n_alive;} ~G()35 ~G() {alive_ = 0; --n_alive;} 36 operator ()()37 void operator()() 38 { 39 assert(alive_ == 1); 40 assert(n_alive >= 1); 41 op_run = true; 42 } 43 }; 44 45 int G::n_alive = 0; 46 bool G::op_run = false; 47 main(int,char **)48int main(int, char**) 49 { 50 { 51 G g; 52 std::thread t0(g); 53 pthread_t pid = t0.native_handle(); 54 assert(pid != 0); 55 t0.join(); 56 } 57 58 return 0; 59 } 60