INNER CODE UNIT · Rust

lock_write

RyanCodrai/turbovec · turbovec-python/src/lib.rs:327

fn lock_write<T>(lock: &std::sync::RwLock<T>) -> std::sync::RwLockWriteGuard<'_, T> {
    lock.write()
        .unwrap_or_else(std::sync::PoisonError::into_inner)
}

/// Run `f` under the write lock, for O(1) ops called while attached to
/// the GIL: try the lock without blocking (the uncontended fast path —
/// cheaper than a GIL detach round-trip), and only when another thread
/// holds it detach and acquire it blocking, so a brief removal never
/// stalls every Python thread behind a long writer.
///
/// The work is a closure rather than a returned guard because a guard
/// cannot cross a GIL release. The previous shape returned one, so the
/// contended path could only wait *detached* and then retry *attached* —
/// acquiring the lock fairly and immediately dropping it. That threw
/// away `RwLock`'s queueing fairness and left progress depending on
/// winning an unsynchronised race against every reader. `search` holds
/// the read lock for its whole detached duration, so one background

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…