about summary refs log tree commit diff
path: root/library/alloc/src/boxed.rs
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-10-02 10:27:52 +0200
committerGitHub <noreply@github.com>2025-10-02 10:27:52 +0200
commit8a18176c92af8ee396049b3f3b70721f2124d663 (patch)
tree3d0ca0bc9096ed7ad24204121cc93c4a28d626ec /library/alloc/src/boxed.rs
parentb78b1070e32dde0c5d3fba9f2bc8506cc042bb3a (diff)
parent3e8ce2bda9e9563c546287b4715fcde61d008d3e (diff)
downloadrust-8a18176c92af8ee396049b3f3b70721f2124d663.tar.gz
rust-8a18176c92af8ee396049b3f3b70721f2124d663.zip
Rollup merge of #147225 - daxpedda:wasm-u-u-atomics-threads, r=alexcrichton
Don't enable shared memory by default with Wasm atomics

This prepares us for a future where LLVM eventually stabilizes the atomics target feature, in which case we don't want to inflate atomics with threads. Otherwise users would be stuck with shared memory even when they don't want it/need it.

### Context

Currently the atomics target features is unstable and can't be used without re-building Std with it (`-Zbuild-std`).
Enabling the atomics target feature automatically enables shared memory.
Shared memory is required to actually allow multi-threading.
However, shared memory comes with a performance overhead when atomic instructions aren't able to be lowered to regular memory access instructions or when interacting with certain Web APIs.
So it is very undesirable to enable shared memory by default for the majority of users.

While it is possible to use atomics without shared memory, the question remains what use-case this scenario has.
The only one I can think of would involve multiple memories, where the main memory remains un-shared but a second shared memory exists. While Rust doesn't support multiple memories, it might be possible with inline assembly (rust-lang/rust#136382).

So alternatively, we might consider *not* enabling atomics by default even when LLVM does. In which case everything would remain the same.

---

This will break current Web multi-threading users. To address this they can add the following `RUSTFLAGS`:
```
-Clink-args=--shared-memory,--max-memory=1073741824,--import-memory,--export=__wasm_init_tls,--export=__tls_size,--export=__tls_align,--export=__tls_base
```

We could add a new experimental flag that enables the right linker arguments for users, but I feel that's not in Rusts scope. Or like suggested before: a Rust-only `threads` target feature.

Addresses rust-lang/rust#77839.
r? ``@alexcrichton``
Diffstat (limited to 'library/alloc/src/boxed.rs')
0 files changed, 0 insertions, 0 deletions