Hi all, I'm trying to create an object that shall be accessed by user of the object and a few threads. Something like this:
pub struct ConnectionManager {
state: Arc<State>,
}
impl ConnectionManager {
pub fn new(event_pipe: IoReceiver<Event>) -> ConnectionManager {
let state = Arc::new(State{ event_pipe: event_pipe });
let weak_state = state.downgrade();
spawn(move || {
start_accepting_connections(weak_state);
});
ConnectionManager { state: state }
}
....
}
But I'm getting errors such as this one:
src/connection_manager.rs:70:5: 70:10 error: the trait `core::marker::Sync` is not implemented for the type `core::cell::UnsafeCell<bool>` [E0277]
src/connection_manager.rs:70 spawn(move || {
^~~~~
src/connection_manager.rs:70:5: 70:10 note: `core::cell::UnsafeCell<bool>` cannot be shared between threads safely
src/connection_manager.rs:70 spawn(move || {
^~~~~
I also tried to pass the Weak pointer to the thread through a mpsc channel, but that gave me a very similar error. Am I missing some idiomatic way of doing this kind of thing in Rust?