Skip to content

Call main only once take 4 #3236

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

Merged
merged 2 commits into from
Jan 13, 2023
Merged

Conversation

daxpedda
Copy link
Collaborator

As discussed in #3092, this addresses the possible race condition if one doesn't use init when compiling the WASM module.

To make this possible I changed the way the start function was modified in various places.
Currently the start function was always taken from the module and then wrapped into a new function, constructing a pretty nested start function.

With this PR the start function is constantly being modified instead of wrapping it over and over again, this allows to use local variables, eg. I stored the current thread counter in a local variable that I can use later to determine if we are in the first thread or not.

I hope it's alright that I put some shared functionality into wasm-bindgen-wasm-conventions.

Replaces #3062, #3092 and #3234.
Fixes #2295.

@daxpedda
Copy link
Collaborator Author

This is ready now @Liamolucko.

@daxpedda daxpedda marked this pull request as ready for review January 13, 2023 14:04
Copy link
Collaborator

@Liamolucko Liamolucko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@Liamolucko Liamolucko merged commit 37bba2f into rustwasm:main Jan 13, 2023
daxpedda added a commit to daxpedda/wasm-bindgen that referenced this pull request Jan 19, 2023
* Modify `module.start` instead of wrapping it

* Call main only once
chemicstry added a commit to chemicstry/wasm_thread that referenced this pull request Mar 10, 2023
wasm-bindgen no longer autostarts main on worker threads:
rustwasm/wasm-bindgen#3236
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to avoid extra calls to main when creating web worker from binary?
2 participants