Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame^] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <thread> |
| 11 | |
| 12 | // class thread |
| 13 | |
| 14 | // bool joinable() const; |
| 15 | |
| 16 | #include <thread> |
| 17 | #include <new> |
| 18 | #include <cstdlib> |
| 19 | #include <cassert> |
| 20 | |
| 21 | class G |
| 22 | { |
| 23 | int alive_; |
| 24 | public: |
| 25 | static int n_alive; |
| 26 | static bool op_run; |
| 27 | |
| 28 | G() : alive_(1) {++n_alive;} |
| 29 | G(const G& g) : alive_(g.alive_) {++n_alive;} |
| 30 | ~G() {alive_ = 0; --n_alive;} |
| 31 | |
| 32 | void operator()() |
| 33 | { |
| 34 | assert(alive_ == 1); |
| 35 | assert(n_alive == 1); |
| 36 | op_run = true; |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | int G::n_alive = 0; |
| 41 | bool G::op_run = false; |
| 42 | |
| 43 | int main() |
| 44 | { |
| 45 | { |
| 46 | std::thread t0((G())); |
| 47 | assert(t0.joinable()); |
| 48 | t0.join(); |
| 49 | assert(!t0.joinable()); |
| 50 | } |
| 51 | } |