Skip to content

Commit 493f2e5

Browse files
committed
Update other.test_{proxy,main}_pthread_join_detach exception
Already-detached threads that are attempting to detach themselves will always cause EDEADLK.
1 parent 44776e8 commit 493f2e5

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec
1717
// Attempt to join a thread which does not point to a valid thread, or
1818
// does not exist anymore.
1919
if (t->self != t) return ESRCH;
20-
// Thread is attempting to join to itself. Already detached threads are
21-
// handled below by returning EINVAL instead.
22-
if (t->detach_state != DT_DETACHED && __pthread_self() == t) return EDEADLK;
20+
// Thread is attempting to join to itself.
21+
if (__pthread_self() == t) return EDEADLK;
2322
#endif
2423
int state, cs, r = 0;
2524
__pthread_testcancel();

tests/other/test_pthread_self_join_detach.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,28 @@ int main() {
2121
pthread_t self = pthread_self();
2222

2323
/*
24-
* Attempts to join the current thread will either generate
25-
* EDEADLK or EINVAL depending on whether has already been
26-
* detached
24+
* Attempts to join the current thread will cause EDEADLK.
2725
*/
2826
int ret = pthread_join(self, NULL);
2927
printf("pthread_join -> %s\n", strerror(ret));
30-
if (is_detached) {
31-
assert(ret == EINVAL);
32-
} else {
33-
assert(ret == EDEADLK);
34-
}
28+
assert(ret == EDEADLK);
3529

3630
/*
3731
* Attempts to detach the main thread will either succeed
3832
* or cause EINVAL if its already been detached.
33+
*
34+
* Note that musl causes EDEADLK when already-detached threads
35+
* are attempting to detach itself, since it re-uses code from
36+
* pthread_join.
3937
*/
4038
ret = pthread_detach(self);
4139
printf("pthread_detach(self) -> %s\n", strerror(ret));
4240
if (is_detached) {
43-
assert(ret == EINVAL);
41+
assert(ret == EDEADLK);
4442
} else {
4543
assert(ret == 0);
4644
}
4745

48-
ret = pthread_join(self, NULL);
49-
printf("pthread_join -> %s\n", strerror(ret));
50-
assert(ret == EINVAL);
51-
5246
puts("passed");
5347

5448
return 0;

0 commit comments

Comments
 (0)