Project Description
A Read-Writer Locker designed in such a way that hard locked cannot happen, upgrading from read locks to write locks are handled automatically, and highly nested locking is allowed.

Forked from jpmikkers' ReaderWriterLockAlt located at http://readerwriterlockalt.codeplex.com/.  As such, this also supports .NET 2.0+.  If you would like to learn how to design your own, or you would like to help with this project, please start there.

Note:  If you would like regular locking (replacing SyncLocks/locks) that cannot be hard locked, simply use this class and only use write locks.

Features
  • No hard locks when dealing with complex locking.
  • No manual upgrade locks. Upgrading locks is as simple as nesting a write lock inside a read lock.
  • Compatibility with ReaderWriterLock and ReaderWriterLockSlim through wrapper classes. This allows migration of existing code to work with this new locker, needing only a minimal amount of code changes. (not implemented yet)
  • The ability to determine where hard locks would occur. You can use this information to correct these places. Then once it is guaranteed to never happen, you can remove the overhead associated with preventing hard locks. (not implemented yet)
  • Aborting a thread while thread locking is occurring won't cause stability issues. Not disposing it won't cause issues either. It is, however, recommended to dispose the locker in both cases for performance reasons. (not finished yet)
  • Portability. The ideas behind this locking mechanism can be applied to many different languages and platforms.
License
This project uses a new Tri-License Choice MIT/L-GPL/MS-PL.  As such, you have a choice of choosing MIT, L-GPL v2 or v3, or MS-PL. Or you can choose to use the tri-license and let others have their choice. While using this tri-license, MIT will be used in regards to the code, and L-GPL v2 for patents (so algorithms remain open source).  Only when MS-PL is chosen, does it apply (dropping MIT and L-GPL).

Problem Solved
The typical lock(A) locking on lock(B), and lock(B) locking on lock(A). I detect when it happens, and let one thread "run its course" to solve this issue.

ReaderWriteLocker 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

Dim Lock As ReadWriteLocker(True)

Using ReadLock As IDisposable = Lock.GetReadLock()
  ' Perform any reading you might need, like iterating through a List.

  Using WriteLock As IDisposable = Lock.GetWriteLock()
    ' Perform any writing you may need, like adding items to that List.

  End Using
End Using


Last edited Sep 19, 2010 at 11:23 PM by TamusJRoyce, version 30