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 |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 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 | int i = 0; |
| 23 | |
Howard Hinnant | 932209b | 2011-05-17 23:32:48 +0000 | [diff] [blame] | 24 | void func(std::promise<void> p) |
Howard Hinnant | f39daa8 | 2010-08-28 21:01:06 +0000 | [diff] [blame] | 25 | { |
| 26 | p.set_value_at_thread_exit(); |
| 27 | i = 1; |
| 28 | } |
| 29 | |
| 30 | int main() |
| 31 | { |
| 32 | { |
| 33 | std::promise<void> p; |
| 34 | std::future<void> f = p.get_future(); |
| 35 | std::thread(func, std::move(p)).detach(); |
| 36 | f.get(); |
| 37 | assert(i == 1); |
| 38 | } |
| 39 | } |