annotate libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // { dg-do run }
kono
parents:
diff changeset
2 // { dg-options "-pthread" }
kono
parents:
diff changeset
3 // { dg-require-effective-target c++11 }
kono
parents:
diff changeset
4 // { dg-require-effective-target pthread }
kono
parents:
diff changeset
5 // { dg-require-cstdint "" }
kono
parents:
diff changeset
6 // { dg-require-gthreads "" }
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 // Copyright (C) 2009-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
9 //
kono
parents:
diff changeset
10 // This file is part of the GNU ISO C++ Library. This library is free
kono
parents:
diff changeset
11 // software; you can redistribute it and/or modify it under the
kono
parents:
diff changeset
12 // terms of the GNU General Public License as published by the
kono
parents:
diff changeset
13 // Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
14 // any later version.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 // This library is distributed in the hope that it will be useful,
kono
parents:
diff changeset
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
19 // GNU General Public License for more details.
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 // You should have received a copy of the GNU General Public License along
kono
parents:
diff changeset
22 // with this library; see the file COPYING3. If not see
kono
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include <future>
kono
parents:
diff changeset
26 #include <testsuite_hooks.h>
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 // Test promise::set_value() for deadlock by checking if the state is ready
kono
parents:
diff changeset
30 // during construction and destruction of the associated state.
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 struct tester
kono
parents:
diff changeset
33 {
kono
parents:
diff changeset
34 tester(int);
kono
parents:
diff changeset
35 tester(const tester&);
kono
parents:
diff changeset
36 tester() = delete;
kono
parents:
diff changeset
37 tester& operator=(const tester&);
kono
parents:
diff changeset
38 };
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 std::promise<tester> pglobal;
kono
parents:
diff changeset
41 std::future<tester> fglobal = pglobal.get_future();
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 auto delay = std::chrono::milliseconds(1);
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 tester::tester(int)
kono
parents:
diff changeset
46 {
kono
parents:
diff changeset
47 VERIFY (fglobal.wait_for(delay) == std::future_status::timeout);
kono
parents:
diff changeset
48 }
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 tester::tester(const tester&)
kono
parents:
diff changeset
51 {
kono
parents:
diff changeset
52 // if this copy happens while a mutex is locked next line could deadlock:
kono
parents:
diff changeset
53 VERIFY (fglobal.wait_for(delay) == std::future_status::timeout);
kono
parents:
diff changeset
54 }
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 tester& tester::operator=(const tester&)
kono
parents:
diff changeset
57 {
kono
parents:
diff changeset
58 // if this copy happens while a mutex is locked next line could deadlock:
kono
parents:
diff changeset
59 VERIFY (fglobal.wait_for(delay) == std::future_status::timeout);
kono
parents:
diff changeset
60 return *this;
kono
parents:
diff changeset
61 }
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 void test01()
kono
parents:
diff changeset
64 {
kono
parents:
diff changeset
65 pglobal.set_value( tester(1) );
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 VERIFY (fglobal.wait_for(delay) == std::future_status::ready);
kono
parents:
diff changeset
68 }
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 int main()
kono
parents:
diff changeset
71 {
kono
parents:
diff changeset
72 test01();
kono
parents:
diff changeset
73 return 0;
kono
parents:
diff changeset
74 }