Improve ConcurrentScheduler closing on exit.

This commit is contained in:
levlam 2020-11-22 23:30:40 +03:00
parent 39f30f42be
commit 155c12edea
2 changed files with 15 additions and 3 deletions

View File

@ -185,9 +185,7 @@ class ClientManager::Impl final {
while (!tds_.empty() && !ExitGuard::is_exited()) {
receive(0.1);
}
if (!ExitGuard::is_exited()) { // prevent closing of schedulers from already killed by OS threads
concurrent_scheduler_->finish();
}
concurrent_scheduler_->finish();
}
private:

View File

@ -11,6 +11,7 @@
#include "td/actor/impl/ActorInfo.h"
#include "td/actor/impl/Scheduler.h"
#include "td/utils/ExitGuard.h"
#include "td/utils/MpscPollableQueue.h"
#include "td/utils/port/thread_local.h"
@ -140,6 +141,19 @@ void ConcurrentScheduler::finish() {
detail::Iocp::Guard iocp_guard(iocp_.get());
#endif
if (ExitGuard::is_exited()) {
// prevent closing of schedulers from already killed by OS threads
for (auto &thread : threads_) {
thread.detach();
}
#if TD_PORT_WINDOWS
iocp_->interrupt_loop();
iocp_thread_.detach();
#endif
return;
}
#if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED
for (auto &thread : threads_) {
thread.join();