473,231 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,231 developers and data experts.

Impossible to hard lock Read-Write Locking

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

It is meant to replace ReaderWriterLock and ReaderWriterLockSlim. 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 ReaderWriterLock and ReaderWriterLockSlim by renaming them to NHLReaderWriterLock and NHLReaderWriterLockSlim 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 ReaderWriterLock/ReaderWriterLockSlim which allows hard locks and instability.

Expand|Select|Wrap|Line Numbers
  1. ReadWriteLocker Lock = New ReadWriteLocker(True);
  3. using (IDisposable ReadLock = Lock.GetReadLock())
  4. {
  5.   // Perform any reading you might need, like iterating through a List.
  7.   using (IDisposable WriteLock = Lock.GetWriteLock())
  8.   {
  9.     // Perform any writing you may need, like adding items to a List.
  11.   } // End using
  12. } // End using
Hopefully helpful,

Sep 22 '10 #1
0 2837

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Antoon Pardon | last post by:
The queue and condition class allow threads to wait only a limited time. However this currently is implemented by a polling loop. Now for those who like to avoid polling I have here a Tlock...
by: /.. | last post by:
Hi all, I'm working on a report display page that currently uses 5 checkboxlists with a total of 86 items to display values from 5 different tables in an Access database. The page works fine...
by: Paul Close | last post by:
How does one make all controls on a Windows form read-only? Controls such as check boxes, combo boxes and date time pickers dont appear to have a read-only property. Disabling the controls makes...
by: Uwe C. Schroeder | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, maybe my mind is stuck, but here's something strange. This is the classic "counter" thing, where you can't / won't use sequences....
by: Rob | last post by:
When you set the enabled property of a text box to False... it is shaded so much that it is hard to read... any suggestions.
by: noleander | last post by:
Ive got a time-critical application that runs on Windows XP and Unix. I've got some timing issues that Ive traced to virtual memory getting paged in and out. I think I can solve the problem if...
by: Alessandro | last post by:
Hi everybody, I tried to find some information about my subject with google, but I didn't find anything. I need to read a text file, process the entire content, then kill. In the meantime I...
by: smnoff | last post by:
Below is a section from string.c at this linkhttp://cvs.opensolaris.org/source/xref/on/usr/src/common/util/string.cthat I am trying to fully understand.I don't fully understand LINE 514; not to...
by: tjonsek | last post by:
I am working with directories in PHP for the first time. I have code that I've changed multiple times to try different things. I would think this is pretty standard fare so I'm not sure why I can't...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.