Skip to content

Commit

Permalink
Merge pull request #482 from eosnetworkfoundation/fix_promise_use
Browse files Browse the repository at this point in the history
Get future before use to avoid race on set_value get_future
  • Loading branch information
linh2931 authored Jun 21, 2022
2 parents cf91de3 + 1884261 commit a4ffdf5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libraries/chain/platform_timer_asio_fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ platform_timer::platform_timer() {

if(refcount++ == 0) {
std::promise<void> p;
auto f = p.get_future();
checktime_thread = std::thread([&p]() {
fc::set_os_thread_name("checktime");
checktime_ios = std::make_unique<boost::asio::io_service>();
Expand All @@ -36,7 +37,7 @@ platform_timer::platform_timer() {

checktime_ios->run();
});
p.get_future().get();
f.get();
}

my->timer = std::make_unique<boost::asio::high_resolution_timer>(*checktime_ios);
Expand Down Expand Up @@ -64,11 +65,12 @@ void platform_timer::start(fc::time_point tp) {
else {
#if 0
std::promise<void> 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()));
Expand Down

0 comments on commit a4ffdf5

Please sign in to comment.