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