Skip to content

Commit

Permalink
js: Properly manage workers when useWorkers is called twice
Browse files Browse the repository at this point in the history
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
zeux committed Oct 29, 2023
1 parent 7073dc2 commit 8a2fc4d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 12 additions & 4 deletions js/meshopt_decoder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions js/meshopt_decoder.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8a2fc4d

Please sign in to comment.