set_value_at_thread_exit_const.pass.cpp (828B)
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 // UNSUPPORTED: libcpp-has-no-threads 11 // UNSUPPORTED: c++98, c++03 12 13 // <future> 14 15 // class promise<R> 16 17 // void promise::set_value_at_thread_exit(const R& r); 18 19 #include <future> 20 #include <cassert> 21 22 void func(std::promise<int> p) 23 { 24 const int i = 5; 25 p.set_value_at_thread_exit(i); 26 } 27 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() == 5); 35 } 36 }