set_lvalue_at_thread_exit_pass.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. // Copyright (C) 2011 Vicente J. Botet Escriba
  10. //
  11. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  12. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  13. // <boost/thread/future.hpp>
  14. // class promise<R>
  15. // void promise<R&>::set_value_at_thread_exit(R& r);
  16. #define BOOST_THREAD_VERSION 4
  17. #include <boost/thread/future.hpp>
  18. #include <boost/detail/lightweight_test.hpp>
  19. #include <memory>
  20. int i = 0;
  21. //void func(boost::promise<int&> p)
  22. boost::promise<int&> p;
  23. void func()
  24. {
  25. p.set_value_at_thread_exit(i);
  26. i = 4;
  27. }
  28. int main()
  29. {
  30. {
  31. //boost::promise<int&> p;
  32. boost::future<int&> f = p.get_future();
  33. //boost::thread(func, boost::move(p)).detach();
  34. boost::thread(func).detach();
  35. int r = f.get();
  36. BOOST_TEST(r == 4);
  37. }
  38. return boost::report_errors();
  39. }