Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Jonathan Roelofs | 8d86b2e | 2014-09-05 19:45:05 +0000 | [diff] [blame] | 9 | // |
| 10 | // UNSUPPORTED: libcpp-has-no-threads |
Eric Fiselier | 031a3d2 | 2015-08-28 05:06:04 +0000 | [diff] [blame] | 11 | // UNSUPPORTED: c++98, c++03 |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 12 | |
| 13 | // <future> |
| 14 | |
| 15 | // class promise<R> |
| 16 | |
| 17 | // void promise<R&>::set_value_at_thread_exit(R& r); |
| 18 | |
| 19 | #include <future> |
| 20 | #include <memory> |
| 21 | #include <cassert> |
| 22 | |
| 23 | int i = 0; |
| 24 | |
Howard Hinnant | 932209b | 2011-05-17 23:32:48 +0000 | [diff] [blame] | 25 | void func(std::promise<int&> p) |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 26 | { |
| 27 | p.set_value_at_thread_exit(i); |
| 28 | i = 4; |
| 29 | } |
| 30 | |
| 31 | int main() |
| 32 | { |
| 33 | { |
| 34 | std::promise<int&> p; |
| 35 | std::future<int&> f = p.get_future(); |
| 36 | std::thread(func, std::move(p)).detach(); |
| 37 | assert(f.get() == 4); |
| 38 | } |
| 39 | } |