2 // { dg-options "-pthread" }
3 // { dg-require-effective-target c++11 }
4 // { dg-require-effective-target pthread }
5 // { dg-require-gthreads "" }
7 // Copyright (C) 2009-2020 Free Software Foundation, Inc.
9 // This file is part of the GNU ISO C++ Library. This library is free
10 // software; you can redistribute it and/or modify it under the
11 // terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 3, or (at your option)
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
24 // Test that promise::set_value throws when required.
27 #include <testsuite_hooks.h>
29 // Check for promise_already_satisfied error conditions.
36 std::future
<int> f1
= p1
.get_future();
45 catch (std::future_error
& e
)
48 std::make_error_code(std::future_errc::promise_already_satisfied
));
52 std::chrono::milliseconds
delay(1);
53 VERIFY( f1
.wait_for(delay
) == std::future_status::ready
);
54 VERIFY( f1
.get() == 1 );
63 std::future
<int> f1
= p1
.get_future();
69 p1
.set_exception(std::make_exception_ptr(4));
72 catch (std::future_error
& e
)
75 std::make_error_code(std::future_errc::promise_already_satisfied
));
79 std::chrono::milliseconds
delay(1);
80 VERIFY( f1
.wait_for(delay
) == std::future_status::ready
);
81 VERIFY( f1
.get() == 3 );
90 std::future
<int> f1
= p1
.get_future();
92 p1
.set_exception(std::make_exception_ptr(4));
99 catch (std::future_error
& e
)
102 std::make_error_code(std::future_errc::promise_already_satisfied
));
106 std::chrono::milliseconds
delay(1);
107 VERIFY( f1
.wait_for(delay
) == std::future_status::ready
);
127 std::promise
<int&> p1
;
128 std::future
<int&> f1
= p1
.get_future();
138 catch (std::future_error
& e
)
141 std::make_error_code(std::future_errc::promise_already_satisfied
));
145 std::chrono::milliseconds
delay(1);
146 VERIFY( f1
.wait_for(delay
) == std::future_status::ready
);
147 VERIFY( f1
.get() == 1 );
155 std::promise
<int&> p1
;
156 std::future
<int&> f1
= p1
.get_future();
163 p1
.set_exception(std::make_exception_ptr(4));
166 catch (std::future_error
& e
)
169 std::make_error_code(std::future_errc::promise_already_satisfied
));
173 std::chrono::milliseconds
delay(1);
174 VERIFY( f1
.wait_for(delay
) == std::future_status::ready
);
175 VERIFY( f1
.get() == 3 );
183 std::promise
<int&> p1
;
184 std::future
<int&> f1
= p1
.get_future();
186 p1
.set_exception(std::make_exception_ptr(4));
194 catch (std::future_error
& e
)
197 std::make_error_code(std::future_errc::promise_already_satisfied
));
201 std::chrono::milliseconds
delay(1);
202 VERIFY( f1
.wait_for(delay
) == std::future_status::ready
);
222 std::promise
<void> p1
;
223 std::future
<void> f1
= p1
.get_future();
232 catch (std::future_error
& e
)
235 std::make_error_code(std::future_errc::promise_already_satisfied
));
239 std::chrono::milliseconds
delay(1);
240 VERIFY( f1
.wait_for(delay
) == std::future_status::ready
);
249 std::promise
<void> p1
;
250 std::future
<void> f1
= p1
.get_future();
256 p1
.set_exception(std::make_exception_ptr(4));
259 catch (std::future_error
& e
)
262 std::make_error_code(std::future_errc::promise_already_satisfied
));
266 std::chrono::milliseconds
delay(1);
267 VERIFY( f1
.wait_for(delay
) == std::future_status::ready
);
276 std::promise
<void> p1
;
277 std::future
<void> f1
= p1
.get_future();
279 p1
.set_exception(std::make_exception_ptr(4));
286 catch (std::future_error
& e
)
289 std::make_error_code(std::future_errc::promise_already_satisfied
));
293 std::chrono::milliseconds
delay(1);
294 VERIFY( f1
.wait_for(delay
) == std::future_status::ready
);
310 // Check for no_state error condition (PR libstdc++/80316)
317 promise
<int> p2(std::move(p1
));
323 catch (std::future_error
& e
)
325 VERIFY(e
.code() == make_error_code(future_errc::no_state
));
334 promise
<int&> p2(std::move(p1
));
341 catch (std::future_error
& e
)
343 VERIFY(e
.code() == make_error_code(future_errc::no_state
));
352 promise
<void> p2(std::move(p1
));
358 catch (std::future_error
& e
)
360 VERIFY(e
.code() == make_error_code(future_errc::no_state
));