Skip to content

Commit

Permalink
Expand comments on miri fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Oct 16, 2024
1 parent 3f1d7ac commit 7c729b8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ unsafe impl crate::Impl for StdCriticalSection {
// SAFETY: As per the acquire/release safety contract, release can only be called
// if the critical section is acquired in the current thread,
// in which case we know the GLOBAL_GUARD is initialized.
//
// We have to `assume_init_read` then drop instead of `assume_init_drop` because:
// - drop requires exclusive access (&mut) to the contents
// - mutex guard drop first unlocks the mutex, then returns. In between those, there's a brief
// moment where the mutex is unlocked but a `&mut` to the contents exists.
// - During this moment, another thread can go and use GLOBAL_GUARD, causing `&mut` aliasing.
#[allow(let_underscore_lock)]
let _ = GLOBAL_GUARD.assume_init_read();

Expand Down

0 comments on commit 7c729b8

Please sign in to comment.