-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 purposes). | ||
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? 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. Yes, prior to this change normal mutex's never make it here since they don't need to track ownership. |
||
|
||
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); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
19526 | ||
19540 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
19527 | ||
19541 |
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; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.