xref: /llvm-project/libcxx/test/std/thread/futures/futures.promise/set_value_at_thread_exit_void.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<void>::set_value_at_thread_exit();
17 
18 #include <future>
19 #include <memory>
20 #include <cassert>
21 
22 #include "make_test_thread.h"
23 #include "test_macros.h"
24 
25 int i = 0;
26 
func(std::promise<void> p)27 void func(std::promise<void> p)
28 {
29     p.set_value_at_thread_exit();
30     i = 1;
31 }
32 
main(int,char **)33 int main(int, char**)
34 {
35     {
36         std::promise<void> p;
37         std::future<void> f = p.get_future();
38         support::make_test_thread(func, std::move(p)).detach();
39         f.get();
40         assert(i == 1);
41     }
42 
43   return 0;
44 }
45