Skip to content

Commit 44d0df9

Browse files
committed
Revert detached check
1 parent ab9e35e commit 44d0df9

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ weak_alias(dummy1, __tl_sync);
1010
static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at)
1111
{
1212
#ifdef __EMSCRIPTEN__
13-
// XXX Emscripten: Add check for invalid (already joined) thread.
13+
// Attempt to join a thread which does not point to a valid thread, or
14+
// does not exist anymore.
1415
if (!_emscripten_thread_is_valid(t)) return ESRCH;
15-
// Thread is attempting to join to itself.
16-
if (__pthread_self() == t) return EDEADLK;
16+
// Thread is attempting to join to itself. Already detached threads are
17+
// handled below by returning EINVAL instead.
18+
// TODO: The detached check here is just to satisfy the
19+
// `other.test_{proxy,main}_pthread_join_detach` tests.
20+
if (t->detach_state != DT_DETACHED && __pthread_self() == t) return EDEADLK;
1721
#endif
1822
int state, cs, r = 0;
1923
__pthread_testcancel();

test/other/test_pthread_self_join_detach.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,17 @@ int main() {
2121
pthread_t self = pthread_self();
2222

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

3036
/*
3137
* Attempts to detach the main thread will either succeed
@@ -39,6 +45,10 @@ int main() {
3945
assert(ret == 0);
4046
}
4147

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

4454
return 0;

0 commit comments

Comments
 (0)