xref: /llvm-project/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_const.pass.cpp (revision a7f9895cc18995549c7facb96e72718da282a864)
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // UNSUPPORTED: no-threads
10 // UNSUPPORTED: c++03
11 
12 // <future>
13 
14 // class promise<R>
15 
16 // void promise::set_value_at_thread_exit(const R& r);
17 
18 #include <future>
19 #include <cassert>
20 
21 #include "make_test_thread.h"
22 #include "test_macros.h"
23 
func(std::promise<int> p)24 void func(std::promise<int> p)
25 {
26     const int i = 5;
27     p.set_value_at_thread_exit(i);
28 }
29 
main(int,char **)30 int main(int, char**)
31 {
32     {
33         std::promise<int> p;
34         std::future<int> f = p.get_future();
35         support::make_test_thread(func, std::move(p)).detach();
36         assert(f.get() == 5);
37     }
38 
39   return 0;
40 }
41