Skip to content

Commit 44776e8

Browse files
committed
Always check whether blocking is allowed
Even when joining already exited threads.
1 parent 7806443 commit 44776e8

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec
3737
r = EINVAL;
3838
break;
3939
}
40-
// Check whether blocking is allowed when the state is joinable.
41-
// This is not necessary for exited threads because they can be
42-
// joined without blocking.
43-
if (state == DT_JOINABLE) emscripten_check_blocking_allowed();
4440
#else
4541
if (state >= DT_DETACHED) a_crash();
4642
#endif
@@ -61,6 +57,9 @@ static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec
6157

6258
int __pthread_join(pthread_t t, void **res)
6359
{
60+
#ifdef __EMSCRIPTEN__ // XXX Emscripten check whether blocking is allowed.
61+
emscripten_check_blocking_allowed();
62+
#endif
6463
return __pthread_timedjoin_np(t, res, 0);
6564
}
6665

tests/pthread/main_thread_join.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <assert.h>
77
#include <emscripten.h>
8-
#include <emscripten/threading.h>
98
#include <pthread.h>
109
#include <stdio.h>
1110

@@ -33,10 +32,6 @@ void *ThreadMain(void *arg) {
3332
// Delay to force the main thread to try and fail a few times before
3433
// succeeding.
3534
while (tries.load() < EXPECTED_TRIES) {}
36-
#else
37-
// Delay a bit to force the main thread to actually block, as exited
38-
// threads can be joined without blocking.
39-
emscripten_thread_sleep(1000);
4035
#endif
4136
pthread_exit((void*)0);
4237
}

0 commit comments

Comments
 (0)