Call Future.wait() in other thread, throws folly::FutureInvalid: Future invalid, although the Future is valid!
- Dominant language
- C++
- Stars
- 30.5k
- Forks
- 5.9k
- PR merge metrics
- No merged PRs in 30d
Description
My code:
```
void FollyIOPoolTask::Cancel() {
// call in thread A
if(!is_start_) {
return;
}
is_start_ = false;
LoggerHelper::LOG_D("FollyIOPoolTask::Cancel, before wait");
if(current_future_.valid()) {
current_future_.cancel();
current_future_.wait();
}
LoggerHelper::LOG_D("FollyIOPoolTask::Cancel, after wait");
}
void FollyIOPoolTask::Start(std::function callback) {
// call in thread B
is_start_ = true;
LoggerHelper::LOG_D("FollyIOPoolTask::task submit to pool!");
current_future_ = folly::via(folly::getGlobalIOExecutor()).then([=](auto&&) {
LoggerHelper::LOG_D("FollyIOPoolTask::task started!");
if(!is_start_) {
return;
}
callback();
LoggerHelper::LOG_D("FollyIOPoolTask::task finish!");
});
}
```
`current_future_` is a member of `FollyIOPoolTask`.
I call `Start()` in thread B, and then I call `Cancel()` in thread A. And it throws:
`terminating with uncaught exception of type folly::FutureInvalid: Future invalid`
Contributor guide
Assessment
This issue has not been assessed yet.