-
Notifications
You must be signed in to change notification settings - Fork 273
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
10.1.2. Base Code / Send and Sync. "Sync + Send" #436
Comments
let v = Arc::new(Unsync);
let clone = v.clone();
thread::spawn(move || {
clone.reference()
});
v.reference() // races with clone.reference() Therefore Similarly, let v = Arc::new(Unsend);
worker.run(|| { // this closure only sends `&v` to the worker thread
thread_local.set(v.clone());
});
drop(v);
worker.run(|| {
let arc = thread_local.get();
let unsend = arc.into_inner();
drop(unsend); // we have somehow sent Unsend into the worker thread
}); The principle is that Arc can be used both by reference (by cloning) and by moving (by obviously sending the Arc), but its underlying reference can also be used as reference (normal Deref) and owned (by |
@SOF3, thank you for your reply. I assume that with I'm not sure what you mean with Having your reply I feel that I'm not mature enough in Rust to fully and clearly understand your explanation, such that I can explain the same to someone else. But the main point of this GitHub issue is not for me to understand, but to see the explanation in the book, the main words of this GitHub issue are: "Would be nice to see in the book the clarification or details about that". Thanks. |
|
10.1.2. Base Code / Send and Sync. Fragment:
It is unclear from the text of the book why the line about
Send
has the fragmentSync +
:and why the line about
Sync
has a fragment+ Send
:Would be nice to see in the book the clarification or details about that.
I also looked at (and it is still unclear)
The text was updated successfully, but these errors were encountered: