-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.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/SoundnessT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
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
briansmith
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.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/SoundnessT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.