Impossible to hard lock Read-Write Locking

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TamusJRoyce
    New Member
    • Apr 2008
    • 108

    #1

    Impossible to hard lock Read-Write Locking

    http://nohardlockrwlocker.codeplex.com/ is a read-write locker I recently designed so hard locks are impossible.

    It is meant to replace ReaderWriterLoc k and ReaderWriterLoc kSlim. Upgrade locks are as simple as placing a write lock inside a read lock.

    It will soon have collections which utilize this locker to cache modifications while enumerations occurs to it. Then after it completes, modifications are applied. This makes enumeration while modification impossible. Even when thread safety turned off inside the locker.

    It also supports setting a thread (such as the UI thread) as a priority thread, so when hard locks do occur, that thread is the one chosen to break the hard lock.

    In addition, the read-write locker allows being a drop-in replacement for ReaderWriterLoc k and ReaderWriterLoc kSlim by renaming them to NHLReaderWriter Lock and NHLReaderWriter LockSlim respectfully (where NHL stands for No Hard Locking). As for hard locks happening to regular SyncLocks/locks, it supports replacing those with non-hard locking regular locks.

    I hope people find this useful over the poorly implemented ReaderWriterLoc k/ReaderWriterLoc kSlim which allows hard locks and instability.

    Code:
    ReadWriteLocker Lock = New ReadWriteLocker(True);
    
    using (IDisposable ReadLock = Lock.GetReadLock())
    {
      // Perform any reading you might need, like iterating through a List.
    
      using (IDisposable WriteLock = Lock.GetWriteLock())
      {
        // Perform any writing you may need, like adding items to a List.
    
      } // End using
    } // End using
    Hopefully helpful,

    TamusJRoyce
Working...