Closed dtolnay closed 2 years ago
We hand out &'static T references onto arbitrary threads when iterating the inventory, so T: Sync is necessary.
&'static T
T: Sync
use std::cell::Cell; use std::thread; struct Thing { cell: Cell<String>, } inventory::collect!(Thing); inventory::submit! { Thing { cell: Cell::new(String::new()), } } fn main() { thread::spawn(move || { let thing = inventory::iter::<Thing>().next().unwrap(); loop { thing.cell.set(".".repeat(40)); } }); let thing = inventory::iter::<Thing>().next().unwrap(); loop { thing.cell.set(String::new()); let _ = thing.cell.take().clone(); } }
double free or corruption (fasttop) Aborted (core dumped)
We hand out
&'static T
references onto arbitrary threads when iterating the inventory, soT: Sync
is necessary.