-
Notifications
You must be signed in to change notification settings - Fork 13.3k
core::marker::Send and raw pointers #21709
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
Comments
This changed recently, leaving the docs out of date. Thanks for noticing and filing a bug! |
@drewcrawford You can use the use std::ptr::Unique;
use std::thread::Thread;
#[derive(Copy)]
struct ShouldBeSendable {
x: i32
}
unsafe impl std::marker::Send for ShouldBeSendable { }
fn main() {
let ptr : *mut ShouldBeSendable = &mut ShouldBeSendable {x: 5}; // this is not `Send`
let sendablePtr = Unique(ptr); // but this is!
let closure = move |:| {
// `sendablePtr` con be moved inside this closure
let ptr = sendablePtr.0; // unpack the raw pointer
println!("{}", unsafe { (*ptr).x })
};
let something = Thread::scoped(closure).join();
} |
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this issue
Mar 19, 2015
Manishearth
added a commit
to Manishearth/rust
that referenced
this issue
Mar 20, 2015
@japaric example for Rust 1.25 using https://play.rust-lang.org/?gist=1ce2532a0eefc60695663c26faddebe1&version=stable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Rust book says that raw pointers "are considered sendable (if their contents is considered sendable)".
However from what I can see, the compiler generates the error
the trait
core::marker::Sendis not implemented for the type
when it encounters a raw pointer to a Sendable type.It could be that I am doing something wrong, it could be that the documentation is unclear or it could be that the error message isn't helpful at indicating whatever the real problem with this code is.
Produces an error:
The text was updated successfully, but these errors were encountered: