Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
js: Properly manage workers when useWorkers is called twice
Before this change, calling useWorkers twice would allocate new workers but keep old workers around; this resulted in old workers leaking when the new count was larger; when the new count was smaller, we would still maintain the worker count but recreate some workers and leak older ones. Instead we now only create more workers if more workers are requested, and if the requested count is smaller than current worker count, we ask some existing workers (nicely) to close by sending a dummy message. Because messages are processed in order, and processing the worker response does not access global workers[], it should be safe to call useWorkers(0) at any point without disrupting already dispatched requests. This also provides a clean way to reclaim all resources used by the workers, including WebAssembly memory.
- Loading branch information