Skip to content

Multithreaded memory allocation #1884

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

Closed
DzmitryFil opened this issue Nov 29, 2019 · 2 comments
Closed

Multithreaded memory allocation #1884

DzmitryFil opened this issue Nov 29, 2019 · 2 comments
Labels

Comments

@DzmitryFil
Copy link

DzmitryFil commented Nov 29, 2019

Am i correct in that memory allocation in raytrace demo (and more generally in multithreaded wasm) compiled with wasm-bindgen is currently broken?

dlmalloc-rs wasm implementation assumes that it is run single-threaded, and it's the default memory allocator in wasm at this point.

Am i missing something? @alexcrichton

Considering Lack of atomic.wait on the main thread it looks like the only way for me to use threads with wasm-bindgen is to manually implement allocator that uses mutexes for global lock, and spinlocks if in main thread?

@DzmitryFil
Copy link
Author

After looking at sys implementation for wasm i found that allocator is actually always spinlocked, and should be safe to use. Was a bit misled by the comments inside dlmalloc-rs and Multithreading Rust and Wasm blogpost from year earlier. Closing.

@alexcrichton
Copy link
Contributor

Yes looks like you answered your own question! Multi-threaded memory allocation works with a spinlock today. It's pretty bad. There's a nice long comment in the source though explaining why we chose the bad route for now.

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

No branches or pull requests

2 participants