Do not try to attach to JVM after exit.

This commit is contained in:
levlam 2020-11-23 00:18:01 +03:00
parent 155c12edea
commit 52653d6bf1
2 changed files with 7 additions and 4 deletions

View File

@ -392,10 +392,12 @@ class MultiImpl {
multi_td_.reset();
Scheduler::instance()->finish();
}
scheduler_thread_.join();
if (!ExitGuard::is_exited()) { // prevent closing of schedulers from already killed by OS threads
concurrent_scheduler_->finish();
if (!ExitGuard::is_exited()) {
scheduler_thread_.join();
} else {
scheduler_thread_.detach();
}
concurrent_scheduler_->finish();
}
private:

View File

@ -7,6 +7,7 @@
#include "td/tl/tl_jni_object.h"
#include "td/utils/common.h"
#include "td/utils/ExitGuard.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Slice.h"
@ -79,7 +80,7 @@ void register_native_method(JNIEnv *env, jclass clazz, std::string name, std::st
std::unique_ptr<JNIEnv, JvmThreadDetacher> get_jni_env(JavaVM *java_vm, jint jni_version) {
JNIEnv *env = nullptr;
if (java_vm->GetEnv(reinterpret_cast<void **>(&env), jni_version) == JNI_EDETACHED) {
if (!ExitGuard::is_exited() && java_vm->GetEnv(reinterpret_cast<void **>(&env), jni_version) == JNI_EDETACHED) {
#ifdef JDK1_2 // if not Android JNI
auto p_env = reinterpret_cast<void **>(&env);
#else