pub trait SyncSlice<T> {
// Required method
fn as_sync_slice(&mut self) -> &[SyncCell<T>];
}Expand description
Required Methods§
Sourcefn as_sync_slice(&mut self) -> &[SyncCell<T>]
fn as_sync_slice(&mut self) -> &[SyncCell<T>]
Returns a &[SyncCell<T>] from a &mut [T].
§Examples
use sync_cell_slice::SyncSlice;
let mut v = vec![1, 2, 3, 4];
// s can be used to write to v from multiple threads
let s = v.as_sync_slice();
std::thread::scope(|scope| {
scope.spawn(|| {
unsafe { s[0].set(5) };
});
scope.spawn(|| {
unsafe { s[1].set(10) };
});
});