You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Our pthread_kill implementation is incorrect, this API is not for killing threads, but sending signals to them #14872
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.
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:
Perhaps we should only support the SIGCANCEL signal? Although deprecated by the POSIX standard, it's still used to implement pthread_cancel internally in musl, which could help move pthread_cancel to native code (see e.g. commit 16970d2).
The problem is that we have no way to deliver SIGCANCEL (or any signal) asynchronously... so we can't interrupt a busy-looping thread. But yes, one possible option is to implement pthread_kill so that it actually does call the signal handler on the respective thread (although it would have to be done in co-operations with the receiving thread). I think you are correct, I will try to do that instead.
Activity
Remove incorrect/non-working (and used?) implementation of pthread_kill
Remove incorrect/non-working (and used?) implementation of pthread_kill
kleisauke commentedon Aug 16, 2021
Perhaps we should only support the
SIGCANCELsignal? Although deprecated by the POSIX standard, it's still used to implementpthread_cancelinternally in musl, which could help movepthread_cancelto native code (see e.g. commit 16970d2).emscripten/system/lib/libc/musl/src/thread/pthread_cancel.c
Line 110 in 0d61898
emscripten/src/library_pthread.js
Lines 761 to 763 in 0d61898
sbc100 commentedon Aug 16, 2021
The problem is that we have no way to deliver SIGCANCEL (or any signal) asynchronously... so we can't interrupt a busy-looping thread. But yes, one possible option is to implement pthread_kill so that it actually does call the signal handler on the respective thread (although it would have to be done in co-operations with the receiving thread). I think you are correct, I will try to do that instead.
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc)
Add improved support for signals (raise, kill, sigaction, etc) (#14883)
Add improved support for signals (raise, kill, sigaction, etc) (emscr…
Remove incorrect/non-working (and used?) implementation of pthread_kill