emscripten-core / emscripten-core/emscripten

Our pthread_kill implementation is incorrect, this API is not for killing threads, but sending signals to them

Open
#14,872 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

`pthread_kill`, just like `kill`, is for sending signal to processes. What is more it seems to specifically not be capable of killing an individual pthread, only directing a signal to be received on a specific thread.

The only way a thread can be killed is if vulunarily exits, and sending a signal to a thread is just one way to ask it to exit. If one actually send `SIGKILL` to a thread it will bring down the entire process, not that just thread.

See https://stackoverflow.com/questions/34258271/pthread-kill-kills-not-just-a-thread-but-the-whole-program for some discussion of this.

We could make a fake implementation of `pthread_kill` but we would only be able to deliver signals to threads that yield in some way and not busy-looping. It seems that we can really only support cooperative receiving of signal which means we probably can't do better than `pthread_cancel` if we want to try to bring down a running thread.

What is more the current test for pthread_kill is currently disabled on chrome because it causes the tab to hang (i.e. worker.terminate() simply doesn't work for busy-looping threads). See: https://github.com/emscripten-core/emscripten/blob/7c8be3dab1218d74c0081636e2321febdacda43f/tests/test_browser.py#L3860

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.