fitzgen / bumpalo

A fast bump allocation arena for Rust
https://docs.rs/bumpalo
Apache License 2.0
1.39k stars 110 forks source link

Implement `Sync` for `Vec`. #72

Closed zakarumych closed 4 years ago

zakarumych commented 4 years ago

It seems that for T: Sync Vec<'bump, T> should implement Sync as well.

fitzgen commented 4 years ago

I think you're correct. The bump arena is not sync, but Vec<'bump, T> won't touch the bump arena unless you have mutable access, which you can't across threads.

Are you interested in submitting a PR?

zakarumych commented 4 years ago

Returning to the issue. There is a way to send &Bump to another thread if Vec would be Sync. So this would be unsound.

let bump = Bump::new();
let v = Vec::new_in(&bump);
std::thread::spawn(|| {
  let mut v2 = v.clone();
  v2.push(42); // Using `bump` from another thread.
});