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

How to avoid extra calls to main when creating web worker from binary? #2295

Closed
kettle11 opened this issue Aug 24, 2020 · 2 comments · Fixed by #3236
Closed

How to avoid extra calls to main when creating web worker from binary? #2295

kettle11 opened this issue Aug 24, 2020 · 2 comments · Fixed by #3236
Labels

Comments

@kettle11
Copy link

kettle11 commented Aug 24, 2020

Summary

For context: I've been experimenting with creating a library that spawns web workers that share memory with each other and the main thread.

I've been basing my experiments off of the Raytrace Parallel example: https://github.com/rustwasm/wasm-bindgen/tree/master/examples/raytrace-parallel

An issue I've run into is that __wbindgen_start is called whenever init is called. So the binary's main is invoked extra times whenever the library tries to spawn a worker and call init for it.

Is there some way to disable the automatic call to __wbindgen_start so that it can be invoked only for the main thread? Or should a special init be introduced for web workers?

Additional Details

Work arounds:

  • Require the binary using the library to insert some sort of check into main to detect that they're on a worker thread.
  • Compile the binary as a lib and manually invoke start
@alexcrichton
Copy link
Contributor

Currently this can't be done, you'll need to orchestrate something without the start function. The way multithreading works is to create an instance on each thread, which inherently runs the start function.

@daxpedda
Copy link
Collaborator

daxpedda commented Sep 2, 2022

@alexcrichton would it be acceptable to add a function like initWithoutStart? Basically a copy of init but without the call to __wbindgen_start() at the end. Or is there some other reason/limitation why this isn't possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants