brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 96ec333 Raw
60 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-threads, libcpp-has-thread-api-external10 11// XFAIL: windows12 13// <thread>14 15// class thread16 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 26class G27{28    int alive_;29public:30    static int n_alive;31    static bool op_run;32 33    G() : alive_(1) {++n_alive;}34    G(const G& g) : alive_(g.alive_) {++n_alive;}35    ~G() {alive_ = 0; --n_alive;}36 37    void operator()()38    {39        assert(alive_ == 1);40        assert(n_alive >= 1);41        op_run = true;42    }43};44 45int G::n_alive = 0;46bool G::op_run = false;47 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