Skip to content

Commit 586b49f

Browse files
committed
Revert "Sync _emscripten_thread_exit() with musl's pthread_exit"
This reverts commit 5df7db5.
1 parent 982b8d2 commit 586b49f

1 file changed

Lines changed: 10 additions & 23 deletions

File tree

system/lib/pthread/pthread_create.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
static void dummy_0() {}
3434
weak_alias(dummy_0, __pthread_tsd_run_dtors);
35-
weak_alias(dummy_0, __do_orphaned_stdio_locks);
36-
weak_alias(dummy_0, __dl_thread_cleanup);
3735

3836
static void __run_cleanup_handlers() {
3937
pthread_t self = __pthread_self();
@@ -315,21 +313,11 @@ void _emscripten_thread_exit(void* result) {
315313
// Call into the musl function that runs destructors of all thread-specific data.
316314
__pthread_tsd_run_dtors();
317315

318-
// If this is the main runtime thread, don't proceed with
319-
// termination of the thread, but prepare for exit to call
320-
// atexit handlers.
321-
if (emscripten_is_main_runtime_thread()) {
322-
exit(0);
323-
}
324-
325-
// At this point we are committed to thread termination.
326-
327-
// The thread list lock must be AS-safe.
328316
__tl_lock();
329317

330-
// Process robust list in userspace to handle non-pshared mutexes
331-
// and the detached thread case where the robust list head will
332-
// be invalid when the kernel would process it.
318+
/* Process robust list in userspace to handle non-pshared mutexes
319+
* and the detached thread case where the robust list head will
320+
* be invalid when the kernel would process it. */
333321
__vm_lock();
334322
volatile void *volatile *rp;
335323
while ((rp=self->robust_list.head) && rp != &self->robust_list.head) {
@@ -346,18 +334,19 @@ void _emscripten_thread_exit(void* result) {
346334
}
347335
__vm_unlock();
348336

349-
__do_orphaned_stdio_locks();
350-
__dl_thread_cleanup();
351-
352-
// Last, unlink thread from the list. This change will not be visible
353-
// until the lock is released via __tl_unlock() below.
354337
if (!--libc.threads_minus_1) libc.need_locks = 0;
338+
355339
self->next->prev = self->prev;
356340
self->prev->next = self->next;
357341
self->prev = self->next = self;
358342

359343
__tl_unlock();
360344

345+
if (emscripten_is_main_runtime_thread()) {
346+
exit(0);
347+
return;
348+
}
349+
361350
// Not hosting a pthread anymore in this worker set __pthread_self to NULL
362351
__set_thread_state(NULL, 0, 0, 1);
363352

@@ -375,10 +364,8 @@ void _emscripten_thread_exit(void* result) {
375364
// When dynamic linking is enabled we need to keep track of zombie threads
376365
_emscripten_thread_exit_joinable(self);
377366
#endif
378-
379-
// Wake any joiner.
380367
a_store(&self->detach_state, DT_EXITED);
381-
__wake(&self->detach_state, 1, 1);
368+
__wake(&self->detach_state, 1, 1); // Wake any joiner.
382369
}
383370
}
384371

0 commit comments

Comments
 (0)