Move pthread_cancel to native code. NFC.#15603
Conversation
system/lib/pthread/pthread_create.c
Outdated
| } | ||
|
|
||
| // Mark as `no_sanitize("address"` since emscripten_pthread_exit destroys | ||
| // Mark as `no_sanitize("address")` since emscripten_pthread_exit destroys |
There was a problem hiding this comment.
Looks like all the changes to this file are just cleanups.. can you split this out?
There was a problem hiding this comment.
OK, reverted those with commit 72da048. I'll make a new PR with these changes soon (perhaps with [skip ci] in the commit message, since these are all minor changes?).
src/worker.js
Outdated
| if (Module['_pthread_self']()) { | ||
| Module['__emscripten_thread_exit'](-1/*PTHREAD_CANCELED*/); | ||
| } | ||
| postMessage({ 'cmd': 'cancelDone' }); |
There was a problem hiding this comment.
I wonder if the removal on cancelDone can be split out into its own change? It seems like a bugfix its own right as __emscripten_thread_exit should always be enough to recycle the thread. That would be very small bugix PR that would simplify this one.
| struct pthread* self = pthread_self(); | ||
| if (self->canceldisable) | ||
| return; | ||
| if (_pthread_isduecanceled(self)) { |
There was a problem hiding this comment.
Can the removal of _pthread_isduecanceled also be split out into its own PR?
| #ifdef __EMSCRIPTEN__ | ||
| pthread_testcancel(); | ||
| #endif | ||
|
|
There was a problem hiding this comment.
I removed this since it looked redundant. This was introduced in commit d2bb705 (which was based on musl 1.0.5), but when musl was updated to 1.1.15 (commit 31cf2bb), it ends up calling __pthread_testcancel twice, see:
emscripten/system/lib/libc/musl/src/thread/pthread_cond_timedwait.c
Lines 185 to 192 in 7e6d511
If preferred, I can also create a separate PR for this.
3008b16 to
1146ba5
Compare
1146ba5 to
d30f858
Compare
d30f858 to
8c66923
Compare
|
Rebased, PTAL. This would make reviewing #15604 easier. |
8c66923 to
90ef01f
Compare
sbc100
left a comment
There was a problem hiding this comment.
Great! (lets just ifdef out a little more of the unused code.. but otherwise looks great!)
| }, | ||
|
|
||
| __emscripten_thread_cleanup: function(thread) { | ||
| // Called when a thread needs to be cleaned up so it can be reused. |
There was a problem hiding this comment.
Perhaps mention that its called in exactly two places: "When a detached thread exits and when an attached thread is joined"?
There was a problem hiding this comment.
Mentioned/elaborated with commit f4058e2.
| } | ||
| #endif | ||
|
|
||
| void __testcancel() |
There was a problem hiding this comment.
If we are including this function, then perhaps we should also be including system/lib/libc/musl/src/thread/pthread_testcancel.c rather than our custom system/lib/pthread/pthread_testcancel.c?
How about ifdef'ing this function out for now and the adding it in as followup PR which includes system/lib/libc/musl/src/thread/pthread_testcancel.c? (i.e. lets keep this PR small and focused.. but we can remove these unused functions).
| return -ECANCELED; | ||
| } | ||
|
|
||
| #ifndef __EMSCRIPTEN__ |
There was a problem hiding this comment.
I think can move this up to line 5, no?
|
Great! |
|
Can you rebase/merge? |
f4058e2 to
0b0d88b
Compare
|
Rebased as requested. |
Split from PR #13007.