Open
Description
use std::thread;
use std::sync::mpsc;
fn main() {
let (send, recv) = mpsc::channel();
let t = thread::spawn(|| {
recv.recv().unwrap();
});
send.send(());
t.join().unwrap();
}
This currently gives the error
<anon>:6:13: 6:26 error: the trait `core::marker::Sync` is not implemented for the type `core::cell::UnsafeCell<std::sync::mpsc::Flavor<()>>` [E0277]
<anon>:6 let t = thread::spawn(|| {
^~~~~~~~~~~~~
<anon>:6:13: 6:26 help: see the detailed explanation for E0277
<anon>:6:13: 6:26 note: `core::cell::UnsafeCell<std::sync::mpsc::Flavor<()>>` cannot be shared between threads safely
<anon>:6:13: 6:26 note: required because it appears within the type `std::sync::mpsc::Receiver<()>`
<anon>:6:13: 6:26 note: required because it appears within the type `[closure@<anon>:6:27: 8:6 recv:&std::sync::mpsc::Receiver<()>]`
<anon>:6:13: 6:26 note: required by `std::thread::spawn`
error: aborting due to previous error
playpen: application terminated with error code 101
If a closure needs to be Sync, we should perhaps suggest that it be made a move closure.
Perhaps we should verify that the closure can be made move (i.e. it is : 'static
when made move), but I'm not sure how easy that is to do.
We already suggest move closures when you do the same thing with a Vec
, because the error reaches borrowck. Typeck sync issues don't suggest move.