Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return detached threads to the pool #8286

Merged
merged 19 commits into from
May 20, 2019
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var LibraryPThread = {
delete Module['canvas'];
#endif

postMessage({ cmd: 'exit' });
postMessage({ cmd: 'exit', threadId: tb });
VirtualTim marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
Expand Down Expand Up @@ -319,18 +319,18 @@ var LibraryPThread = {
err('Thread ' + d.threadId + ': ' + d.text);
} else if (d.cmd === 'alert') {
alert('Thread ' + d.threadId + ': ' + d.text);
} else if (d.cmd === 'exit') {
// Thread is exiting, no-op here
} else if (d.cmd === 'exitProcess') {
// A pthread has requested to exit the whole application process (runtime).
Module['noExitRuntime'] = false;
exit(d.returnCode);
} else if (d.cmd === 'cancelDone') {
PThread.freeThreadData(worker.pthread);
worker.pthread = undefined; // Detach the worker from the pthread object, and return it to the worker pool as an unused worker.
PThread.unusedWorkerPool.push(worker);
// TODO: Free if detached.
PThread.runningWorkers.splice(PThread.runningWorkers.indexOf(worker.pthread), 1); // Not a running Worker anymore.
} else if (d.cmd === 'exit' || d.cmd === 'cancelDone') {
var detached = Atomics.load(HEAPU32, (d.threadId + {{{ C_STRUCTS.pthread.detached }}} ) >> 2);
VirtualTim marked this conversation as resolved.
Show resolved Hide resolved
if (detached) {
PThread.freeThreadData(worker.pthread);
worker.pthread = undefined; // Detach the worker from the pthread object, and return it to the worker pool as an unused worker.
PThread.unusedWorkerPool.push(worker);
PThread.runningWorkers.splice(PThread.runningWorkers.indexOf(worker.pthread), 1); // Not a running Worker anymore.
}
} else if (d.cmd === 'objectTransfer') {
PThread.receiveObjectTransfer(e.data);
} else if (e.data.target === 'setimmediate') {
Expand Down