Skip to content

Instantly share code, notes, and snippets.

@dmarce1
Created September 14, 2015 21:53
Show Gist options
  • Save dmarce1/ce35b52e77daed69d2e3 to your computer and use it in GitHub Desktop.
Save dmarce1/ce35b52e77daed69d2e3 to your computer and use it in GitHub Desktop.
future::wait_for test
#include <hpx/hpx.hpp>
#include <boost/chrono.hpp>
#include <boost/thread/thread.hpp>
int hpx_main() {
const auto timeout_time = boost::posix_time::time_duration(boost::posix_time::seconds(1));
while(true) {
auto start_time = boost::chrono::high_resolution_clock::now();
decltype(start_time) end_time;
auto f = hpx::async([&](){
end_time = boost::chrono::high_resolution_clock::now();
});
if( f.wait_for(timeout_time) == hpx::lcos::future_status::timeout ) {
end_time = boost::chrono::high_resolution_clock::now();
boost::chrono::duration<double> dif = end_time - start_time;
printf( "Future timed out after %e seconds. ", dif.count() );
break;
} else {
f.get();
}
end_time = boost::chrono::high_resolution_clock::now();
boost::chrono::duration<double> dif = end_time - start_time;
printf( "Future took %e seconds\n", dif.count() );
}
exit(0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment