Skip to content

Instantly share code, notes, and snippets.

@oberstet
Created March 24, 2014 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oberstet/9749964 to your computer and use it in GitHub Desktop.
Save oberstet/9749964 to your computer and use it in GitHub Desktop.
oberstet@vbox-ubuntu1310:~/scm/AutobahnCpp$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
clang++ -o build/test/test8 -stdlib=libc++ -pthread build/test/test8.o -L/home/oberstet/boost_1_55_0/stage/lib -L/home/oberstet/msgpack_clang/lib -lboost_thread -lboost_system
scons: done building targets.
oberstet@vbox-ubuntu1310:~/scm/AutobahnCpp$ ./build/test/test8
done:
^C
oberstet@vbox-ubuntu1310:~/scm/AutobahnCpp$ ldd ./build/test/test8
linux-vdso.so.1 => (0x00007fffe47fe000)
libboost_thread.so.1.55.0 => /home/oberstet/boost_1_55_0/stage/lib/libboost_thread.so.1.55.0 (0x00007fae54a4c000)
libboost_system.so.1.55.0 => /home/oberstet/boost_1_55_0/stage/lib/libboost_system.so.1.55.0 (0x00007fae54847000)
libc++.so.1 => /usr/lib/x86_64-linux-gnu/libc++.so.1 (0x00007fae54543000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fae5423f000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fae54028000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fae53e0b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fae53a43000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fae5383a000)
/lib64/ld-linux-x86-64.so.2 (0x00007fae54c68000)
oberstet@vbox-ubuntu1310:~/scm/AutobahnCpp$ cat test/test8.cpp
// clang++ -o test8 -std=c++11 -stdlib=libc++ -lboost_thread -lboost_system -I/home/oberstet/boost_1_55_0 -L/home/oberstet/boost_1_55_0/stage/lib test8.cpp
#include <iostream>
// http://stackoverflow.com/questions/22597948/using-boostfuture-with-then-continuations/
#define BOOST_THREAD_PROVIDES_FUTURE
#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#include <boost/thread/future.hpp>
struct Foo {
boost::future<int> start() {
return p.get_future();
}
void finish() {
p.set_value(666);
}
boost::promise<int> p;
};
#define V1
//#define V2
//#define V3
int main () {
Foo foo;
#ifdef V1
// does NOT work
foo.start().then([](boost::future<int> f) {
std::cout << "done:" << std::endl;
std::cout << f.get() << std::endl;
});
#endif
#ifdef V2
// does NOT work
boost::future<int> f0 = foo.start();
f0.then([](boost::future<int> f) {
std::cout << "done:" << std::endl;
std::cout << f.get() << std::endl;
});
#endif
#ifdef V3
// this DOES work
boost::future<void> f2 = foo.start().then([](boost::future<int> f) {
std::cout << "done:" << std::endl;
std::cout << f.get() << std::endl;
});
#endif
foo.finish();
}
oberstet@vbox-ubuntu1310:~/scm/AutobahnCpp$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment