Skip to content

Commit 3008b16

Browse files
committed
Revert cancelDone removal
1 parent 8db22b9 commit 3008b16

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

src/library_pthread.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ var LibraryPThread = {
280280
assert(worker.pthread);
281281
#endif
282282
PThread.returnWorkerToPool(worker);
283+
} else if (cmd === 'cancelDone') {
284+
PThread.returnWorkerToPool(worker);
283285
} else if (d.target === 'setimmediate') {
284286
// Worker wants to postMessage() to itself to implement setImmediate()
285287
// emulation.
@@ -458,17 +460,19 @@ var LibraryPThread = {
458460
#endif
459461
var pthread = PThread.pthreads[pthread_ptr];
460462
// If pthread has been removed from this map this also means that pthread_ptr points
461-
// to already freed data. Such situation may occur in following circumstance:
462-
// Joining thread from non-main browser thread (this also includes thread running main()
463-
// when compiled with `PROXY_TO_PTHREAD`) - in such situation it may happen that following
464-
// code flow occur (MB - Main Browser Thread, S1, S2 - Worker Threads):
465-
// S2: thread ends, 'exit' message is sent to MB
466-
// S1: calls pthread_join(S2), this causes:
467-
// a. S2 is marked as detached,
468-
// b. 'cleanupThread' message is sent to MB.
469-
// MB: handles 'exit' message, as thread is detached, so returnWorkerToPool()
470-
// is called and all thread related structs are freed/released.
471-
// MB: handles 'cleanupThread' message which calls this function.
463+
// to already freed data. Such situation may occur in following circumstances:
464+
// 1. Joining cancelled thread - in such situation it may happen that pthread data will
465+
// already be removed by handling 'cancelDone' message.
466+
// 2. Joining thread from non-main browser thread (this also includes thread running main()
467+
// when compiled with `PROXY_TO_PTHREAD`) - in such situation it may happen that following
468+
// code flow occur (MB - Main Browser Thread, S1, S2 - Worker Threads):
469+
// S2: thread ends, 'exit' message is sent to MB
470+
// S1: calls pthread_join(S2), this causes:
471+
// a. S2 is marked as detached,
472+
// b. 'cleanupThread' message is sent to MB.
473+
// MB: handles 'exit' message, as thread is detached, so returnWorkerToPool()
474+
// is called and all thread related structs are freed/released.
475+
// MB: handles 'cleanupThread' message which calls this function.
472476
if (pthread) {
473477
{{{ makeSetValue('pthread_ptr', C_STRUCTS.pthread.self, 0, 'i32') }}};
474478
var worker = pthread.worker;

src/worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ self.onmessage = function(e) {
280280
if (Module['_pthread_self']()) {
281281
Module['__emscripten_thread_exit'](-1/*PTHREAD_CANCELED*/);
282282
}
283+
postMessage({ 'cmd': 'cancelDone' });
283284
} else if (e.data.target === 'setimmediate') {
284285
// no-op
285286
} else if (e.data.cmd === 'processThreadQueue') {

0 commit comments

Comments
 (0)