Skip to content

pauldotknopf/sharp-read-write-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.
    {
        
    }
}

About

A dumb lib to help manage read/write locks.

Resources

Stars

Watchers

Forks

Packages

No packages published