~ubuntu-branches/ubuntu/trusty/libc++/trusty

« back to all changes in this revision

Viewing changes to libcxx/test/thread/thread.threads/thread.thread.class/thread.thread.assign/move.pass.cpp

  • Committer: Package Import Robot
  • Author(s): Andrej Belym
  • Date: 2012-06-02 19:25:47 UTC
  • Revision ID: package-import@ubuntu.com-20120602192547-b6ta950a8ckc9um2
Tags: upstream-1.0~svn160132
ImportĀ upstreamĀ versionĀ 1.0~svn160132

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
// <thread>
 
11
 
 
12
// class thread
 
13
 
 
14
// thread& operator=(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
void f1()
 
53
{
 
54
    std::exit(0);
 
55
}
 
56
 
 
57
int main()
 
58
{
 
59
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
60
    std::set_terminate(f1);
 
61
    {
 
62
        assert(G::n_alive == 0);
 
63
        assert(!G::op_run);
 
64
        std::thread t0(G(), 5, 5.5);
 
65
        std::thread::id id = t0.get_id();
 
66
        std::thread t1;
 
67
        t1 = std::move(t0);
 
68
        assert(t1.get_id() == id);
 
69
        assert(t0.get_id() == std::thread::id());
 
70
        t1.join();
 
71
        assert(G::n_alive == 0);
 
72
        assert(G::op_run);
 
73
    }
 
74
    {
 
75
        std::thread t0(G(), 5, 5.5);
 
76
        std::thread::id id = t0.get_id();
 
77
        std::thread t1;
 
78
        t0 = std::move(t1);
 
79
        assert(false);
 
80
    }
 
81
#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
82
}