It is likely that the worker needs to be yielded back to the browser's event loop in order for the .terminate() command (called by emscripten_destroy_worker) to apply.
You'll likely need to cooperatively track cancellation state in the worker, and abort doing the computation if user does cancel in the middle of execution. Synchronously sleeping will likely not affect the situation. On Tue, Oct 26, 2021 at 7:44 PM Ben Wiley <[email protected]> wrote: > > I have a program compiled with Emscripten to WebAssembly. Every time I start > processing data (which can take awhile) I spin up a worker with > emscripten_create_worker. And I give the user an option to cancel. But if the > user starts and stops the work repeatedly we can end up with several > concurrent workers, despite only the most recent worker being valuable. On > mobile platforms I'm able to make the program run out of WASM memory by > quickly cycling between start/cancel even though I allow the program to > dynamically grow memory. > > I tried killing the worker on cancel using emscripten_destroy_worker, but > when I profiled my program afterward with Chrome performance tools, I saw > that the workers continue to run to completion, in concurrence. In other > words it seems like emscripten_destroy_worker isn't doing anything. > > Is there a secret to killing a worker that is still running? Do I need to > sleep in the middle of execution? > > Ben > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/emscripten-discuss/CAOD6y0jkT9TSG0eiyJQyGa%2Bb%2Bxn3TFrS3WCV6Jvr_gqNxDodNw%40mail.gmail.com. -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CA%2B6sJ-0jP-4FL320FH0MA-Lo5Mq20yx_0uJ9jF2_M8f6r8Zu2A%40mail.gmail.com.
