Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.1 KiB
C++
Raw Permalink Normal View History

2010-05-11 19:42:16 +00:00
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2010-05-11 19:42:16 +00:00
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads
2010-05-11 19:42:16 +00:00
// <thread>
// class thread
// bool joinable() const;
#include <thread>
#include <new>
#include <cstdlib>
#include <cassert>
#include "test_macros.h"
2010-05-11 19:42:16 +00:00
class G
{
int alive_;
public:
static int n_alive;
static bool op_run;
G() : alive_(1) {++n_alive;}
G(const G& g) : alive_(g.alive_) {++n_alive;}
~G() {alive_ = 0; --n_alive;}
void operator()()
{
assert(alive_ == 1);
assert(n_alive >= 1);
2010-05-11 19:42:16 +00:00
op_run = true;
}
};
int G::n_alive = 0;
bool G::op_run = false;
2019-02-04 20:31:13 +00:00
int main(int, char**)
2010-05-11 19:42:16 +00:00
{
{
G g;
std::thread t0(g);
2010-05-11 19:42:16 +00:00
assert(t0.joinable());
t0.join();
assert(!t0.joinable());
}
2019-02-04 20:31:13 +00:00
return 0;
2010-05-11 19:42:16 +00:00
}