-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
sbc100
wants to merge
1
commit into
emscripten-core:main
Choose a base branch
from
sbc100:deadlock_detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−6
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -53,6 +53,12 @@ int __pthread_mutex_trylock_owner(pthread_mutex_t *m) | |||||
} | ||||||
#endif | ||||||
|
||||||
#if defined(__EMSCRIPTEN__) || !defined(NDEBUG) | ||||||
// We can get here for normal mutexes too, but only in debug builds | ||||||
// (where we track ownership purely for debug purposed). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if ((type & 15) == PTHREAD_MUTEX_NORMAL) return 0; | ||||||
#endif | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can we get here? Is it because of one of the changes in this PR? |
||||||
|
||||||
next = self->robust_list.head; | ||||||
m->_m_next = next; | ||||||
m->_m_prev = &self->robust_list.head; | ||||||
|
@@ -71,8 +77,11 @@ int __pthread_mutex_trylock_owner(pthread_mutex_t *m) | |||||
|
||||||
int __pthread_mutex_trylock(pthread_mutex_t *m) | ||||||
{ | ||||||
#if !defined(__EMSCRIPTEN__) || defined(NDEBUG) | ||||||
/* XXX EMSCRIPTEN always take the slow path in debug builds so we can trap rather than deadlock */ | ||||||
if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL) | ||||||
return a_cas(&m->_m_lock, 0, EBUSY) & EBUSY; | ||||||
#endif | ||||||
return __pthread_mutex_trylock_owner(m); | ||||||
} | ||||||
|
||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
19526 | ||
19540 |
2 changes: 1 addition & 1 deletion
2
test/other/codesize/test_codesize_minimal_pthreads_memgrowth.size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
19527 | ||
19541 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <assert.h> | ||
#include <pthread.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
|
||
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; | ||
|
||
int main() { | ||
printf("in main\n"); | ||
sbc100 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int rtn = pthread_mutex_lock(&m); | ||
assert(rtn == 0); | ||
|
||
// Attempt to lock a second time. In debug builds this should | ||
// hit an assertion. In release builds this will deadlock and | ||
// never return. | ||
pthread_mutex_lock(&m); | ||
printf("should never get here\n"); | ||
sbc100 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert(false); | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.