emscripten-core / emscripten-core/emscripten
Worker cannot terminate Correctly
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
there are two Questions
1.
terminateAllThreads function is not called in the main thread, so that no workers can be terminated, they still in the PThread.unusedWorkers Array and PThread.runningWorkers Array
```javascript
terminateAllThreads: function () {
for (var t in PThread.pthreads) {
var pthread = PThread.pthreads[t];
if (pthread && pthread.worker) {
PThread.returnWorkerToPool(pthread.worker);
}
}
PThread.pthreads = {};
// !!!!! PThread.unusedWorkers is forever a empty Array, beacause of not in the main thread
for (var i = 0; i < PThread.unusedWorkers.length; ++i) {
var worker = PThread.unusedWorkers[i];
assert(!worker.pthread);
worker.terminate();
}
PThread.unusedWorkers = [];
// !!!! runningWorkers too
for (var i = 0; i < PThread.runningWorkers.length; ++i) {
var worker = PThread.runningWorkers[i];
var pthread = worker.pthread;
assert(pthread, 'This Worker should have a pthread it is executing');
PThread.freeThreadData(pthread);
worker.terminate();
}
PThread.runningWorkers = [];
},
```
----------------
2.
i use emcc to compile and run ffmpeg, when i call cwrap to run ffmpeg, for example, there will 30 workers are created, when the command finish, there only 29 workers will be moved into PThread.unusedWorkers, and 1 workers still in the PThread.runningWorkers and will never be terminated.
if i run many times command, there will be lots of workers in the PThread.runningWorkers which cannot recycle by returnWorkersToPool function and generate an OOM error
I dont know if these two questions are bugs ? or the design is so, Looking forward to your reply
Contributor guide
Assessment
This issue has not been assessed yet.