1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
14 // class packaged_task<R(ArgTypes...)>
16 // void operator()(ArgTypes... args);
21 #include "make_test_thread.h"
22 #include "test_macros.h"
29 explicit A(long i
) : data_(i
) {}
31 long operator()(long i
, long j
) const
39 void func0(std::packaged_task
<double(int, char)> p
)
41 std::this_thread::sleep_for(std::chrono::milliseconds(500));
45 void func1(std::packaged_task
<double(int, char)> p
)
47 std::this_thread::sleep_for(std::chrono::milliseconds(500));
51 void func2(std::packaged_task
<double(int, char)> p
)
53 #ifndef TEST_HAS_NO_EXCEPTIONS
58 catch (const std::future_error
& e
)
60 assert(e
.code() == make_error_code(std::future_errc::promise_already_satisfied
));
67 void func3(std::packaged_task
<double(int, char)> p
)
69 #ifndef TEST_HAS_NO_EXCEPTIONS
74 catch (const std::future_error
& e
)
76 assert(e
.code() == make_error_code(std::future_errc::no_state
));
86 std::packaged_task
<double(int, char)> p(A(5));
87 std::future
<double> f
= p
.get_future();
88 support::make_test_thread(func0
, std::move(p
)).detach();
89 assert(f
.get() == 105.0);
91 #ifndef TEST_HAS_NO_EXCEPTIONS
93 std::packaged_task
<double(int, char)> p(A(5));
94 std::future
<double> f
= p
.get_future();
95 support::make_test_thread(func1
, std::move(p
)).detach();
103 assert(e(3, 97) == 106.0);
107 std::packaged_task
<double(int, char)> p(A(5));
108 std::future
<double> f
= p
.get_future();
109 std::thread t
= support::make_test_thread(func2
, std::move(p
));
110 assert(f
.get() == 105.0);
114 std::packaged_task
<double(int, char)> p
;
115 std::thread t
= support::make_test_thread(func3
, std::move(p
));