From 3fce516c394cb44000e1bf8bf394623e65ef2087 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 22 Jul 2020 08:12:52 -0500 Subject: [PATCH] Get future before use to avoid race on set_value get_future --- libraries/chain/platform_timer_asio_fallback.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/chain/platform_timer_asio_fallback.cpp b/libraries/chain/platform_timer_asio_fallback.cpp index a9094267e8..a372dee8e2 100644 --- a/libraries/chain/platform_timer_asio_fallback.cpp +++ b/libraries/chain/platform_timer_asio_fallback.cpp @@ -28,6 +28,7 @@ platform_timer::platform_timer() { if(refcount++ == 0) { std::promise p; + auto f = p.get_future(); checktime_thread = std::thread([&p]() { fc::set_os_thread_name("checktime"); checktime_ios = std::make_unique(); @@ -36,7 +37,7 @@ platform_timer::platform_timer() { checktime_ios->run(); }); - p.get_future().get(); + f.get(); } my->timer = std::make_unique(*checktime_ios); @@ -64,11 +65,12 @@ void platform_timer::start(fc::time_point tp) { else { #if 0 std::promise p; + auto f = p.get_future(); checktime_ios->post([&p,this]() { expired = 0; p.set_value(); }); - p.get_future().get(); + f.get(); #endif expired = 0; my->timer->expires_after(std::chrono::microseconds(x.count()));