-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Move pthread_cancel to native code. NFC. #15603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like all the changes to this file are just cleanups.. can you split this out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| struct pthread* self = pthread_self(); | ||
| if (self->canceldisable) | ||
| return; | ||
| if (_pthread_isduecanceled(self)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the removal of _pthread_isduecanceled also be split out into its own PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| #ifdef __EMSCRIPTEN__ | ||
| pthread_testcancel(); | ||
| #endif | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 (e == ECANCELED) { | |
| __pthread_testcancel(); | |
| __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); | |
| } | |
| #ifdef __EMSCRIPTEN__ | |
| pthread_testcancel(); | |
| #endif |
If preferred, I can also create a separate PR for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned/elaborated with commit f4058e2.
| } | ||
| #endif | ||
|
|
||
| void __testcancel() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return -ECANCELED; | ||
| } | ||
|
|
||
| #ifndef __EMSCRIPTEN__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think can move this up to line 5, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, fixed with commit f4058e2.
|
Great! |
|
Can you rebase/merge? |
f4058e2 to
0b0d88b
Compare
|
Rebased as requested. |
Split from PR #13007.