thread-mgr: Prevent an already detached thread from being detached again (#1487)

If WASM app has called pthread_detach() to detach a thread, it will be detached again
when thread exits. Attempting to detach an already detached thread may result in crash
in musl-libc. This patch fixes it.
This commit is contained in:
Shengyun Zhou 2022-09-15 17:13:33 +08:00 committed by GitHub
parent bbea005db6
commit edaff3c6ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -705,7 +705,7 @@ wasm_cluster_detach_thread(WASMExecEnv *exec_env)
os_mutex_unlock(&cluster_list_lock); os_mutex_unlock(&cluster_list_lock);
return 0; return 0;
} }
if (exec_env->wait_count == 0) { if (exec_env->wait_count == 0 && !exec_env->thread_is_detached) {
/* Only detach current thread when there is no other thread /* Only detach current thread when there is no other thread
joining it, otherwise let the system resources for the joining it, otherwise let the system resources for the
thread be released after joining */ thread be released after joining */