summaryrefslogtreecommitdiffstats
path: root/test/std/thread/futures/futures.promise/set_value_at_thread_exit_void.pass.cpp
blob: 8c092084668ddb51dd001fc5d4d195231ef8cefc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// UNSUPPORTED: libcpp-has-no-threads

// <future>

// class promise<R>

// void promise<void>::set_value_at_thread_exit();

#include <future>
#include <memory>
#include <cassert>

int i = 0;

void func(std::promise<void> p)
{
    p.set_value_at_thread_exit();
    i = 1;
}

int main()
{
    {
        std::promise<void> p;
        std::future<void> f = p.get_future();
        std::thread(func, std::move(p)).detach();
        f.get();
        assert(i == 1);
    }
}