ブーストの今後の継続について質問です。次のコードを検討してください。
#define BOOST_THREAD_PROVIDES_FUTURE
#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
#define BOOST_THREAD_PROVIDES_FUTURE_UNWRAP
#include <boost/thread.hpp>
#include <boost/thread/future.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <iostream>
boost::future<int> test() {
return boost::async([]() {
for(int i = 0; i < 10; ++i){
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
}
return 10;});
}
int main(int argc, char *argv[])
//boost::future<int> f1 = test();
boost::future<int> f1 = test().then([](boost::future<int>&& f) {
return test();});
int result = f1.get();
std::cout <<f1.is_ready();
f1.wait();
std::cout<<" "<<f1.is_ready() <<std::endl;
}
私の意見では、これは1 1
コマンドラインに表示されるはずです。代わりに私は得る0 0
。これは継続の予想される動作ですか?
行のコメントアウト
boost::future<int> f1 = test().then([](boost::future<int>&& f)
{return test();});
そして行のコメントを外します
//boost::future<int> f1 = test();
期待どおりの結果が得られます。
g++ 5.2.0
とVisual Studio 2010
でboost-1.57
テスト済みboost-1.59
。
助けてくれてありがとう。