Skip to content

Latest commit

 

History

History
37 lines (27 loc) · 893 Bytes

README.md

File metadata and controls

37 lines (27 loc) · 893 Bytes

SharpReadWriteLock

A dumb lib to help manage read/write locks.

SharpReadWriteLock

Example

IReadWriteLocker locker = new ReadWriteLocker();

using (await locker.WriteLock("unique-key"))
{
    using (var l = await locker.ReadLock("unique-key", TimeSpan.FromSeconds(10)))
    {
        // Timeout, l == null, because there is currently a write lock.
    }

    using (var l = await locker.ReadLock("unique-key")) // Dead lock here.
    {
        
    }
}

using (await locker.ReadLock("unique-key"))
{
    using (var l = await locker.ReadLock("unique-key"))
    {
        // All good
    }

    using (var l = await locker.WriteLock("unique-key")) // Dead lock here, someone is currently reading.
    {
        
    }
}