Here is the simplified code I am trying to write:
use parking_lot::RwLock;
let buffers: Box<[RwLock<MyBuffer>]> = Box::new([ ... ]);
let (sender, receiver) = std::sync::mpsc::channel();
thread::spawn(move || {
let guard = buffers[ ... ].write().unwrap();
expensive_computation(&mut *guard);
sender.send(guard.downgrade()).unwrap();
});
for message in receiver.iter() {
// Handle the message
}
However, RwLockReadGuard
is not Send
, so this code does not compile.
How should I solve the problem of sending a RwLockReadGuard
across the thread boundary?