Home | History | Annotate | Download | only in futures.promise
      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<void>::set_value_at_thread_exit();
     18 
     19 #include <future>
     20 #include <memory>
     21 #include <cassert>
     22 
     23 int i = 0;
     24 
     25 void func(std::promise<void> p)
     26 {
     27     p.set_value_at_thread_exit();
     28     i = 1;
     29 }
     30 
     31 int main()
     32 {
     33     {
     34         std::promise<void> p;
     35         std::future<void> f = p.get_future();
     36         std::thread(func, std::move(p)).detach();
     37         f.get();
     38         assert(i == 1);
     39     }
     40 }
     41