Skip to content

[musl] Always cancelasync as a boolean. NFC#26532

Merged
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:cancelasync
Mar 24, 2026
Merged

[musl] Always cancelasync as a boolean. NFC#26532
sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100:cancelasync

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Mar 24, 2026

This is how all the other code in musl already treats it.

@sbc100 sbc100 requested review from dschuff and kripken March 24, 2026 15:55
@sbc100 sbc100 enabled auto-merge (squash) March 24, 2026 15:56
This is how all the other code in musl already treats it.
@kripken
Copy link
Member

kripken commented Mar 24, 2026

Hmm, this is what I see when I grep?

system/lib/libc/musl/src/thread/pthread_create.c:	self->cancelasync = 0;
system/lib/libc/musl/src/thread/__timedwait.c:	    self->cancelasync) {
system/lib/libc/musl/src/thread/__timedwait.c:				// In the case of cancelasync or PTHREAD_CANCEL_ENABLE we can just call
system/lib/libc/musl/src/thread/pthread_setcanceltype.c:	if (old) *old = self->cancelasync;
system/lib/libc/musl/src/thread/pthread_setcanceltype.c:	self->cancelasync = new;
system/lib/libc/musl/src/thread/pthread_cancel.c:	// by cancelling cooperatively when self->cancelasync is set.
system/lib/libc/musl/src/thread/pthread_cancel.c:	if (self->canceldisable == PTHREAD_CANCEL_ENABLE || self->cancelasync)
system/lib/libc/musl/src/thread/pthread_cancel.c:	if (self->cancelasync) {
system/lib/libc/musl/src/thread/pthread_cancel.c:	// See comment above about cancelasync under emscripten.
system/lib/libc/musl/src/thread/pthread_cancel.c:	if (self->cancel && (self->cancelasync || !self->canceldisable))
system/lib/libc/musl/src/thread/pthread_cancel.c:		if (t->canceldisable == PTHREAD_CANCEL_ENABLE && t->cancelasync)
system/lib/libc/musl/src/internal/pthread_impl.h:	volatile unsigned char canceldisable, cancelasync;
system/lib/libc/musl/src/time/timer_create.c:	self->cancelasync = 0;

Can't pthread_setcanceltype write a non-boolean value there?

@kripken
Copy link
Member

kripken commented Mar 24, 2026

Or do you mean all reads treat it as a boolean, not altogether?

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 24, 2026

Can't pthread_setcanceltype write a non-boolean value there?

Yes but that would be meaningless/undefined.

The two possible values are:

#define PTHREAD_CANCEL_DEFERRED 0                                                    
#define PTHREAD_CANCEL_ASYNCHRONOUS 1    

if you pass 2 I'm not sure what it would mean, but musl happen to treat that as non-zero/PTHREAD_CANCEL_ASYNCHRONOUS everywhere.

@sbc100
Copy link
Collaborator Author

sbc100 commented Mar 24, 2026

Or do you mean all reads treat it as a boolean, not altogether?

All the checks are withing the musl codebase are basically boolean checks.

Sure you could pass an invalid value to pthread_setcanceltype but that would be undefined behaviour (this change actually makes that undefined behaviour consistent between emscripten-written code and musl-internal code).

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I think it is cleaner to use the constant names, but I guess this API is not going to change, and following musl's conventions is reasonable.

@sbc100 sbc100 merged commit a95d758 into emscripten-core:main Mar 24, 2026
38 checks passed
@sbc100 sbc100 deleted the cancelasync branch March 24, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants