Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <thread> |
| 11 | |
| 12 | // class thread |
| 13 | |
| 14 | // thread(thread&& t); |
| 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 | void operator()(int i, double j) |
| 40 | { |
| 41 | assert(alive_ == 1); |
| 42 | assert(n_alive == 1); |
| 43 | assert(i == 5); |
| 44 | assert(j == 5.5); |
| 45 | op_run = true; |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | int G::n_alive = 0; |
| 50 | bool G::op_run = false; |
| 51 | |
| 52 | int main() |
| 53 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 54 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | { |
| 56 | assert(G::n_alive == 0); |
| 57 | assert(!G::op_run); |
| 58 | std::thread t0(G(), 5, 5.5); |
| 59 | std::thread::id id = t0.get_id(); |
| 60 | std::thread t1 = std::move(t0); |
| 61 | assert(t1.get_id() == id); |
| 62 | assert(t0.get_id() == std::thread::id()); |
| 63 | t1.join(); |
| 64 | assert(G::n_alive == 0); |
| 65 | assert(G::op_run); |
| 66 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 67 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | } |