Skip to content

Conversation

@shengyun-zhou
Copy link
Contributor

If WASM app has called pthread_detach() to detach a thread, it will be detached again at thread exit. Attempting to detach an already detached thread results crash in musl-libc. This patch will fix it.

Comment on lines 700 to 701
if (exec_env->thread_is_detached)
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should move the code into the lock/unlock code piece, e.g. :

    os_mutex_lock(&cluster_list_lock);
    if (exec_env->thread_is_detached) {
        os_mutex_unlock(&cluster_list_lock);
        return 0;
    }
    if (!clusters_have_exec_env(exec_env)) {
    ...
    os_mutex_unlock(&cluster_list_lock);

Or if another thread changes the state when current thread runs between L701 and L705, current thread will change again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have moved it into lock protection.

@wenyongh wenyongh merged commit edaff3c into bytecodealliance:main Sep 15, 2022
@shengyun-zhou shengyun-zhou deleted the thread-mgr-fix branch September 16, 2022 09:24
vickiegpt pushed a commit to vickiegpt/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…ain (bytecodealliance#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants