Improve ConcurrentScheduler closing on exit.
This commit is contained in:
parent
39f30f42be
commit
155c12edea
@ -185,10 +185,8 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
TdReceiver receiver_;
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user