Skip to content

Commit 1580251

Browse files
authored
Remove now-unneeded check in library_pthread.js. NFC (#17015)
The race condition decribed in this comment is no longer possible because the very fist statement `S2: thread ends, 'exit' message is sent to MB` is no longer true. When a non-detached thread exits it no longer sends any kind of message back to the main thread. It simply sets it own `detach_state` to `DT_EXITED`.
1 parent 1cfdb43 commit 1580251

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

src/library_pthread.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -468,23 +468,10 @@ var LibraryPThread = {
468468
assert(pthread_ptr, 'Internal Error! Null pthread_ptr in cleanupThread!');
469469
#endif
470470
var pthread = PThread.pthreads[pthread_ptr];
471-
// If pthread has been removed from this map this also means that pthread_ptr points
472-
// to already freed data. Such situation may occur in following circumstance:
473-
// Joining thread from non-main browser thread (this also includes thread running main()
474-
// when compiled with `PROXY_TO_PTHREAD`) - in such situation it may happen that following
475-
// code flow occur (MB - Main Browser Thread, S1, S2 - Worker Threads):
476-
// S2: thread ends, 'exit' message is sent to MB
477-
// S1: calls pthread_join(S2), this causes:
478-
// a. S2 is marked as detached,
479-
// b. 'cleanupThread' message is sent to MB.
480-
// MB: handles 'exit' message, as thread is detached, so returnWorkerToPool()
481-
// is called and all thread related structs are freed/released.
482-
// MB: handles 'cleanupThread' message which calls this function.
483-
if (pthread) {
484-
{{{ makeSetValue('pthread_ptr', C_STRUCTS.pthread.self, 0, 'i32') }}};
485-
var worker = pthread.worker;
486-
PThread.returnWorkerToPool(worker);
487-
}
471+
assert(pthread);
472+
{{{ makeSetValue('pthread_ptr', C_STRUCTS.pthread.self, 0, 'i32') }}};
473+
var worker = pthread.worker;
474+
PThread.returnWorkerToPool(worker);
488475
},
489476

490477
#if MAIN_MODULE

0 commit comments

Comments
 (0)