Crate seqlock [] [src]

This library provides the SeqLock type, which is a form of reader-writer lock that is heavily optimized for readers.

In certain situations, SeqLock can be two orders of magnitude faster than the standard library RwLock type. Another advantage is that readers cannot starve writers: a writer will never block even if there are readers currently accessing the SeqLock.

The only downside of SeqLock is that it only works on types that are Copy. This means that it is unsuitable for types that contains pointers to owned data.

You should instead use RwLock from the parking_lot crate if you need a reader-writer lock for types that are not Copy.

Examples

use seqlock::SeqLock;

let lock = SeqLock::new(5);

{
    // Writing to the data involves a lock
    let mut w = lock.lock_write();
    *w += 1;
    assert_eq!(*w, 6);
}

{
    // Reading the data is a very fast operation
    let r = lock.read();
    assert_eq!(r, 6);
}

Structs

SeqLock

A sequential lock

SeqLockGuard

RAII structure used to release the exclusive write access of a SeqLock when dropped.