• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <future>
11 
12 // class promise<R>
13 
14 // void promise<R&>::set_value_at_thread_exit(R& r);
15 
16 #include <future>
17 #include <memory>
18 #include <cassert>
19 
20 int i = 0;
21 
func(std::promise<int &> p)22 void func(std::promise<int&> p)
23 {
24     p.set_value_at_thread_exit(i);
25     i = 4;
26 }
27 
main()28 int main()
29 {
30     {
31         std::promise<int&> p;
32         std::future<int&> f = p.get_future();
33         std::thread(func, std::move(p)).detach();
34         assert(f.get() == 4);
35     }
36 }
37