Skip to content

Commit a3c997b

Browse files
committed
revert 4.0.11 debug deadlock slow patch changes, resolves #26619
1 parent 6f7004e commit a3c997b

8 files changed

Lines changed: 15 additions & 35 deletions

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,3 +602,4 @@ a license to everyone to use it as detailed in LICENSE.)
602602
* Christian Lloyd <clloyd@teladochealth.com> (copyright owned by Teladoc Health, Inc.)
603603
* Sean Morris <sean@seanmorr.is>
604604
* Mitchell Wills <mwills@google.com> (copyright owned by Google, Inc.)
605+
* Eugene Hopkinson <slowriot@armchair.software>

system/lib/libc/musl/src/thread/pthread_mutex_lock.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
int __pthread_mutex_lock(pthread_mutex_t *m)
44
{
5-
#if !defined(__EMSCRIPTEN__) || defined(NDEBUG)
6-
/* XXX EMSCRIPTEN always take the slow path in debug builds so we can trap rather than deadlock */
75
if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
86
&& !a_cas(&m->_m_lock, 0, EBUSY))
97
return 0;
10-
#endif
118

129
return __pthread_mutex_timedlock(m, 0);
1310
}

system/lib/libc/musl/src/thread/pthread_mutex_timedlock.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include "pthread_impl.h"
22

3-
#ifdef __EMSCRIPTEN__
4-
#include <assert.h>
5-
#endif
6-
73
#ifndef __EMSCRIPTEN__
84
#define IS32BIT(x) !((x)+0x80000000ULL>>32)
95
#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
@@ -61,12 +57,9 @@ static int pthread_mutex_timedlock_pi(pthread_mutex_t *restrict m, const struct
6157

6258
int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at)
6359
{
64-
#if !defined(__EMSCRIPTEN__) || defined(NDEBUG)
65-
/* XXX EMSCRIPTEN always take the slow path in debug builds so we can trap rather than deadlock */
6660
if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
6761
&& !a_cas(&m->_m_lock, 0, EBUSY))
6862
return 0;
69-
#endif
7063

7164
int type = m->_m_type;
7265
int r, t, priv = (type & 128) ^ 128;
@@ -89,11 +82,6 @@ int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec
8982
if ((type&3) == PTHREAD_MUTEX_ERRORCHECK
9083
&& own == __pthread_self()->tid)
9184
return EDEADLK;
92-
#if defined(__EMSCRIPTEN__) && !defined(NDEBUG)
93-
// Extra check for deadlock in debug builds, but only if we would block
94-
// forever (at == NULL).
95-
assert(at || own != __pthread_self()->tid && "pthread mutex deadlock detected");
96-
#endif
9785

9886
a_inc(&m->_m_waiters);
9987
t = r | 0x80000000;

system/lib/libc/musl/src/thread/pthread_mutex_trylock.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ int __pthread_mutex_trylock_owner(pthread_mutex_t *m)
5353
}
5454
#endif
5555

56-
#if defined(__EMSCRIPTEN__) || !defined(NDEBUG)
57-
// We can get here for normal mutexes too, but only in debug builds
58-
// (where we track ownership purely for debug purposes).
59-
if ((type & 15) == PTHREAD_MUTEX_NORMAL) return 0;
60-
#endif
61-
6256
next = self->robust_list.head;
6357
m->_m_next = next;
6458
m->_m_prev = &self->robust_list.head;
@@ -77,11 +71,8 @@ int __pthread_mutex_trylock_owner(pthread_mutex_t *m)
7771

7872
int __pthread_mutex_trylock(pthread_mutex_t *m)
7973
{
80-
#if !defined(__EMSCRIPTEN__) || defined(NDEBUG)
81-
/* XXX EMSCRIPTEN always take the slow path in debug builds so we can trap rather than deadlock */
8274
if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL)
8375
return a_cas(&m->_m_lock, 0, EBUSY) & EBUSY;
84-
#endif
8576
return __pthread_mutex_trylock_owner(m);
8677
}
8778

test/codesize/test_codesize_minimal_pthreads.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 7363,
33
"a.out.js.gz": 3604,
4-
"a.out.nodebug.wasm": 19003,
5-
"a.out.nodebug.wasm.gz": 8786,
6-
"total": 26366,
7-
"total_gz": 12390,
4+
"a.out.nodebug.wasm": 18991,
5+
"a.out.nodebug.wasm.gz": 8771,
6+
"total": 26354,
7+
"total_gz": 12375,
88
"sent": [
99
"a (memory)",
1010
"b (exit)",

test/codesize/test_codesize_minimal_pthreads_memgrowth.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.out.js": 7765,
33
"a.out.js.gz": 3810,
4-
"a.out.nodebug.wasm": 19004,
5-
"a.out.nodebug.wasm.gz": 8787,
6-
"total": 26769,
7-
"total_gz": 12597,
4+
"a.out.nodebug.wasm": 18992,
5+
"a.out.nodebug.wasm.gz": 8772,
6+
"total": 26757,
7+
"total_gz": 12582,
88
"sent": [
99
"a (memory)",
1010
"b (exit)",

test/other/test_pthread_mutex_deadlock.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ int main() {
1010
int rtn = pthread_mutex_lock(&m);
1111
assert(rtn == 0);
1212

13-
// Attempt to lock a second time. In debug builds this should
14-
// hit an assertion. In release builds this will deadlock and
15-
// never return.
13+
// Attempt to lock a second time. In debug builds with the #24607 behavior
14+
// enabled this should hit an assertion. Without that behavior it deadlocks.
1615
pthread_mutex_lock(&m);
1716
printf("should never get here\n");
1817
assert(false);

test/test_other.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11721,6 +11721,10 @@ def test_pthread_reuse(self):
1172111721
def test_pthread_hello(self, args):
1172211722
self.do_other_test('test_pthread_hello.c', args)
1172311723

11724+
# Preserved for future reinstatement of the debug deadlock check from #24607.
11725+
# This rollback intentionally removes that behavior and returns debug builds to
11726+
# the pre-4.0.11 fast-path behavior for PTHREAD_MUTEX_NORMAL.
11727+
@disabled('disabled by revert-pthread-mutex-debug-deadlock-detection rollback')
1172411728
@crossplatform
1172511729
@requires_pthreads
1172611730
def test_pthread_mutex_deadlock(self):

0 commit comments

Comments
 (0)