Skip to content

Commit b3632b8

Browse files
authored
Remove special case from pthread_kill. (#26668)
This special handling for `SIGCANCEL` should not be needed. If we need to do something like `_emscripten_runtime_keepalive_clear` during pthread cancelation it would be best done when the cancellation in processed in `__testcancel`/`__cancel`. The comment & code I'm removing here was added back in #22467 along with testing in the form of `test/pthread/test_pthread_kill.c` and the pthread_kill tests in posixtest. I recently expanded the testing in #26663, and this change doesn't break any of those tests.
1 parent 670b4c7 commit b3632b8

1 file changed

Lines changed: 4 additions & 24 deletions

File tree

system/lib/pthread/pthread_kill.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,8 @@
1212

1313
#include "pthread_impl.h"
1414

15-
static void do_raise(int sig) {
16-
if (sig == SIGCANCEL) {
17-
// For `SIGCANCEL` there is no need to actually call raise to run the
18-
// handler function. The calling thread (the one calling `pthread_cancel`)
19-
// will already have marked us as being cancelled. All we need to do is
20-
// ensure that `pthread_testcancel` is eventually called and that will cause
21-
// this thread to exit. We can't call `pthread_testcancel` here (since we
22-
// are being called from the proxy queue process and we don't want to leave
23-
// that in a bad state by unwinding). Instead, we rely on
24-
// `pthread_testcancel` at the end of `_emscripten_check_mailbox`. Before
25-
// we return, we do want to make sure we clear the keepalive state so that
26-
// the thread will exit even if it has a reason to stay alive. TODO(sbc):
27-
// Is this the correct behaviour, should `pthread_cancel` instead wait for
28-
// threads to be done with outstanding work/event loops?
29-
_emscripten_runtime_keepalive_clear();
30-
return;
31-
}
32-
raise(sig);
33-
}
34-
35-
static void proxied_do_raise(void* arg) {
36-
do_raise((intptr_t)arg);
15+
static void proxied_raise(void* arg) {
16+
raise((intptr_t)arg);
3717
}
3818

3919
int pthread_kill(pthread_t t, int sig) {
@@ -48,9 +28,9 @@ int pthread_kill(pthread_t t, int sig) {
4828
// The job of pthread_kill is basically to run the (process-wide) signal
4929
// handler on the target thread.
5030
if (pthread_equal(pthread_self(), t)) {
51-
do_raise(sig);
31+
raise(sig);
5232
} else {
53-
emscripten_proxy_async(emscripten_proxy_get_system_queue(), t, proxied_do_raise, (void*)(intptr_t)sig);
33+
emscripten_proxy_async(emscripten_proxy_get_system_queue(), t, proxied_raise, (void*)(intptr_t)sig);
5434
}
5535
return 0;
5636
}

0 commit comments

Comments
 (0)