-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
Description
Right now, MutexGuard<Cell<i32>> satisfies the Sync bound. That is rather bad, because it lets me write a program that has a data race:
use std::sync::Mutex;
use std::cell::Cell;
extern crate rayon;
fn main()
{
let m = Mutex::new(Cell::new(0));
let g = m.lock().unwrap();
{
rayon::join(
|| { g.set(g.get() + 1); println!("Thread 1: {:?}", g.get()) },
|| { g.set(g.get() + 1); println!("Thread 2: {:?}", g.get()) });
}
}The get and set calls in the two threads are unsynchronized (as usual for a Cell), and they are racing. This is a soundness bug.
The cause for this is that MutexGuard<T> implements Sync whenever T implements Send, which is plain wrong. The fix is to let MutexGuard<T> implement Sync whenever T implements Sync. I will submit a PR soon.
Kixunil, johnp, StefanoD, timvisee, zzeroo and 24 more
Metadata
Metadata
Assignees
Labels
I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness