2010-08-28 23:01:06 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2010-11-16 23:09:02 +01:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-08-28 23:01:06 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// <future>
|
|
|
|
|
|
|
|
// class promise<R>
|
|
|
|
|
|
|
|
// void promise<R&>::set_value_at_thread_exit(R& r);
|
|
|
|
|
|
|
|
#include <future>
|
|
|
|
#include <memory>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
2011-05-18 01:32:48 +02:00
|
|
|
void func(std::promise<int&> p)
|
2010-08-28 23:01:06 +02:00
|
|
|
{
|
|
|
|
p.set_value_at_thread_exit(i);
|
|
|
|
i = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::promise<int&> p;
|
|
|
|
std::future<int&> f = p.get_future();
|
|
|
|
std::thread(func, std::move(p)).detach();
|
|
|
|
assert(f.get() == 4);
|
|
|
|
}
|
|
|
|
}
|