This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Promise, future and thread on C++0x

I try this program on Linux Ubuntu and GCC(G++) 4.5.2 that use Promise and

#include <iostream>
#include <future>
#include <thread>

using namespace std;

void myAsyncFun(promise<int> intPromise)
int result;
try {
// calculate the result
result = 25;
catch (std::exception& e)

int main()
promise<int> intPromise;
future<int> intFuture = intPromise.get_future();
std::thread t(myAsyncFun, std::move(intPromise));
// do some other stuff
int result = intFuture.get(); // may throw MyException
cout<<"Result from thread: "<<result<<endl;
return 0;

I get a compiler error:

/usr/include/c++/4.5/future|855|error: deleted function
âstd:promise<_Res>:promise(const std:promise<_Res>&) [with _Res = int,
std:promise<_Res> = std:promise<int>]â|

/usr/include/c++/4.5/thread|141|error: used here|

/usr/include/c++/4.5/thread|141|error: initializing argument 2 of
âstd::_Bind<typename std::_Maybe_wrap_member_pointer<_Tp>::type(_ArgTypes
...)> std::bind(_Functor, _ArgTypes ...) [with _Functor = void
(*)(std:promise<int>), _ArgTypes = {std:romise<int>}, typename
std::_Maybe_wrap_member_pointer<_Tp>::type = void (*)(std:promise<int>)]â|

View this message in context:
Sent from the gcc - libstdc++ mailing list archive at

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]