Skip to content

Add pthread mutex deadlock detection for debug builds #24607

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 18, 2025

This would really have helped in at least detecting the deadlock that was found in #24570 / #24565

@sbc100 sbc100 force-pushed the deadlock_detection branch from a57b588 to 0e10a5e Compare June 18, 2025 23:59
@sbc100 sbc100 requested review from brendandahl, kripken and juj June 18, 2025 23:59
@sbc100 sbc100 force-pushed the deadlock_detection branch from 0e10a5e to efb88c5 Compare June 19, 2025 00:02
if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
&& !a_cas(&m->_m_lock, 0, EBUSY))
return 0;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Should upstream do the same for all platforms? I'm just trying to understand if this is a general improvement or if it works around a specific problem in wasm.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think its a general improvement for debug builds yes. I guess most libc's don't ship debug builds like we do (especially automatically selecting debug libs based on command line flags, which emcc does is quite unusual).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Upstream musl doesn't really have any/many assertions AFAICT, so its not something they tend to consider I suppose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, it looks like upstream musl only has assertion in 2 very specific places:

src/regex/regcomp.c
src/malloc/mallocng/..

No other assertions in whole of libc.

This would really have helped in at least detecting the deadlock that
was found in emscripten-core#24570 / emscripten-core#24565
@sbc100 sbc100 force-pushed the deadlock_detection branch from efb88c5 to a8d3d3f Compare June 19, 2025 14:20
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