Fix ConcurrentScheduler destructor.

This commit is contained in:
levlam 2020-11-22 20:40:47 +03:00
parent 172c08a991
commit 39f30f42be
2 changed files with 5 additions and 4 deletions

View File

@ -44,7 +44,7 @@ class ConcurrentScheduler : private Scheduler::Callback {
void test_one_thread_run(); void test_one_thread_run();
bool is_finished() { bool is_finished() const {
return is_finished_.load(std::memory_order_relaxed); return is_finished_.load(std::memory_order_relaxed);
} }
@ -84,10 +84,10 @@ class ConcurrentScheduler : private Scheduler::Callback {
private: private:
enum class State { Start, Run }; enum class State { Start, Run };
State state_ = State::Start; State state_ = State::Start;
std::mutex at_finish_mutex_;
std::vector<std::function<void()>> at_finish_; // can be used during destruction by Scheduler destructors
std::vector<unique_ptr<Scheduler>> schedulers_; std::vector<unique_ptr<Scheduler>> schedulers_;
std::atomic<bool> is_finished_{false}; std::atomic<bool> is_finished_{false};
std::mutex at_finish_mutex_;
std::vector<std::function<void()>> at_finish_;
#if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED #if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED
std::vector<thread> threads_; std::vector<thread> threads_;
#endif #endif

View File

@ -13,6 +13,7 @@
#include "td/actor/impl/EventFull.h" #include "td/actor/impl/EventFull.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/ExitGuard.h"
#include "td/utils/format.h" #include "td/utils/format.h"
#include "td/utils/List.h" #include "td/utils/List.h"
#include "td/utils/logging.h" #include "td/utils/logging.h"
@ -245,7 +246,7 @@ void Scheduler::clear() {
CHECK(ready_actors_list_.empty()); CHECK(ready_actors_list_.empty());
poll_.clear(); poll_.clear();
if (callback_) { if (callback_ && !ExitGuard::is_exited()) {
// can't move lambda with unique_ptr inside into std::function // can't move lambda with unique_ptr inside into std::function
auto ptr = actor_info_pool_.release(); auto ptr = actor_info_pool_.release();
callback_->register_at_finish([ptr] { delete ptr; }); callback_->register_at_finish([ptr] { delete ptr; });