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 // <future>
     11 
     12 // class promise<R>
     13 
     14 // void promise<void>::set_value_at_thread_exit();
     15 
     16 #include <future>
     17 #include <memory>
     18 #include <cassert>
     19 
     20 int i = 0;
     21 
     22 void func(std::promise<void> p)
     23 {
     24     p.set_value_at_thread_exit();
     25     i = 1;
     26 }
     27 
     28 int main()
     29 {
     30     {
     31         std::promise<void> p;
     32         std::future<void> f = p.get_future();
     33         std::thread(func, std::move(p)).detach();
     34         f.get();
     35         assert(i == 1);
     36     }
     37 }
     38