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<R&>::set_value_at_thread_exit(R& r); 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<int &> p)27void func(std::promise<int&> p) 28 { 29 p.set_value_at_thread_exit(i); 30 i = 4; 31 } 32 main(int,char **)33int main(int, char**) 34 { 35 { 36 std::promise<int&> p; 37 std::future<int&> f = p.get_future(); 38 support::make_test_thread(func, std::move(p)).detach(); 39 assert(f.get() == 4); 40 } 41 42 return 0; 43 } 44