Closed
Description
I tried running this code in miri:
#![feature(reentrant_lock)]
use std::cell::Cell;
use std::sync::ReentrantLock;
use std::thread::scope;
fn main() {
let l = ReentrantLock::new(Cell::new(0u8));
let lg = l.lock();
scope(|s| {
s.spawn(|| dbg!(lg.get()));
lg.set(1);
});
}
I expected to see this happen: compile error
Instead, this happened: compiled successfully and miri reported a data race
this is because the automatic impl<T: Send> Sync for ReentrantLockGuard<T>
is incorrect:
https://doc.rust-lang.org/1.78.0/std/sync/struct.ReentrantLockGuard.html#impl-Sync-for-ReentrantLockGuard%3C'a,+T%3E
ReentrantLock's tracking issue: #121440