63 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10 11// <thread>12 13// class thread14 15// id get_id() const;16 17#include <thread>18#include <new>19#include <cstdlib>20#include <cassert>21 22#include "make_test_thread.h"23#include "test_macros.h"24 25class G26{27 int alive_;28public:29 static int n_alive;30 static bool op_run;31 32 G() : alive_(1) {++n_alive;}33 G(const G& g) : alive_(g.alive_) {++n_alive;}34 ~G() {alive_ = 0; --n_alive;}35 36 void operator()()37 {38 assert(alive_ == 1);39 assert(n_alive >= 1);40 op_run = true;41 }42};43 44int G::n_alive = 0;45bool G::op_run = false;46 47int main(int, char**)48{49 {50 G g;51 std::thread t0 = support::make_test_thread(g);52 std::thread::id id0 = t0.get_id();53 std::thread t1;54 std::thread::id id1 = t1.get_id();55 assert(t0.get_id() == id0);56 assert(id0 != id1);57 assert(t1.get_id() == std::thread::id());58 t0.join();59 }60 61 return 0;62}63