]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/libcxx/thread/thread.threads/thread.thread.class/thread.thread.member/native_handle.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / libcxx / thread / thread.threads / thread.thread.class / thread.thread.member / native_handle.pass.cpp
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 // <thread>
13
14 // class thread
15
16 // native_handle_type native_handle();
17
18 #include <thread>
19 #include <new>
20 #include <cstdlib>
21 #include <cassert>
22
23 class G
24 {
25     int alive_;
26 public:
27     static int n_alive;
28     static bool op_run;
29
30     G() : alive_(1) {++n_alive;}
31     G(const G& g) : alive_(g.alive_) {++n_alive;}
32     ~G() {alive_ = 0; --n_alive;}
33
34     void operator()()
35     {
36         assert(alive_ == 1);
37         assert(n_alive >= 1);
38         op_run = true;
39     }
40 };
41
42 int G::n_alive = 0;
43 bool G::op_run = false;
44
45 int main()
46 {
47     {
48         G g;
49         std::thread t0(g);
50         pthread_t pid = t0.native_handle();
51         assert(pid != 0);
52         t0.join();
53     }
54 }