Closed
Description
Code
fn main() {
let ptr = &false as *const bool;
std::thread::spawn(move || println!("{:p}", ptr)).join().unwrap();
}
Current output
error[E0277]: `*const bool` cannot be sent between threads safely
--> src/main.rs:4:24
|
4 | std::thread::spawn(move || println!("{:p}", ptr)).join().unwrap();
| ------------------ -------^^^^^^^^^^^^^^^^^^^^^^
| | |
| | `*const bool` cannot be sent between threads safely
| | within this `[closure@src/main.rs:4:24: 4:31]`
| required by a bound introduced by this call
|
= help: within `[closure@src/main.rs:4:24: 4:31]`, the trait `Send` is not implemented for `*const bool`
= note: consider using `std::sync::Arc<*const bool>`; for more information visit <https://doc.rust-lang.org/book/ch16-03-shared-state.html>
note: required because it's used within this closure
--> src/main.rs:4:24
|
4 | std::thread::spawn(move || println!("{:p}", ptr)).join().unwrap();
| ^^^^^^^
note: required by a bound in `spawn`
--> /rustc/08d00b40aef2017fe6dba3ff7d6476efa0c10888/library/std/src/thread/mod.rs:680:1
Desired output
No response
Rationale and extra context
Filing to track the hesitation from #88936 (review).
[@nagisa]— Use of
Arc
is not always applicable, as bothSend
andSync
impls forArc<T>
requireT: Send + Sync
. Unless we can verifyT
bounds here, I don't think thison
clause adds any more clarity over the defaultnote
?
[@estebank]— Thats fair, but was concerned the default would be too verbose for a case where we could be more straightforward. I can change it.
[@nagisa]— Well, we can always change this later too. r=me if you don't want to change it.
If T is not Send then Arc<T> is also not Send. Suggesting Arc<T> whenever Send is not implemented seems misguided.
Other cases
No response
Anything else?
No response