Created
September 14, 2015 21:53
-
-
Save dmarce1/ce35b52e77daed69d2e3 to your computer and use it in GitHub Desktop.
future::wait_for test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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