1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // UNSUPPORTED: libcpp-has-no-threads, libcpp-has-thread-api-external 11 12 // XFAIL: windows 13 14 // <thread> 15 16 // class thread 17 18 // native_handle_type native_handle(); 19 20 #include <thread> 21 #include <new> 22 #include <cstdlib> 23 #include <cassert> 24 25 class G 26 { 27 int alive_; 28 public: 29 static int n_alive; 30 static bool op_run; 31 G()32 G() : alive_(1) {++n_alive;} G(const G & g)33 G(const G& g) : alive_(g.alive_) {++n_alive;} ~G()34 ~G() {alive_ = 0; --n_alive;} 35 operator ()()36 void operator()() 37 { 38 assert(alive_ == 1); 39 assert(n_alive >= 1); 40 op_run = true; 41 } 42 }; 43 44 int G::n_alive = 0; 45 bool G::op_run = false; 46 main()47int main() 48 { 49 { 50 G g; 51 std::thread t0(g); 52 pthread_t pid = t0.native_handle(); 53 assert(pid != 0); 54 t0.join(); 55 } 56 } 57