Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 164185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:41:58+00:00 2026-05-11T11:41:58+00:00

In any DBMS that’s more than half-baked, there is a distinction between a read

  • 0

In any DBMS that’s more than half-baked, there is a distinction between a read lock and an update lock. In my multi-threaded C# code, I have, to date, used the lock keyword, but today it came to me that performance in my application would be a lot better if I could make this read vs write distinction in locking; I have many threads that could safely read at the same time, but they obstruct each other for the sake of the infrequent but inevitable writes.

I could, and I suppose I will have to, implement my own locking scheme in which the request for a write-lock both stalls the acquisition of further read locks and is stalled until the extant read locks are released.

None of this is profoundly difficult, and all of it is described in stupefying detail by Date and others in any database theory text you care to name.

Surely I’m not the first to face this need? What’s out there, particularly for C#?


Thank you, Dmitri.

The other thing I hoped for was any experiences and comments people might have on the strengths and weaknesses of any libraries you may have tried.

Good heavens, that’s in System.Core! Stop it, Dmitri, you’re making me feel old.

I wonder what’s the most practical way to lobby Microsoft to provide syntactical sugar similar to the lock (object) { ... } syntax.

Adapted from the MSDN sample

public class SynchronizedCache {   private ReaderWriterLockSlim cacheLock = new ReaderWriterLockSlim();   private Dictionary<int, string> innerCache = new Dictionary<int, string>();    public string Read(int key)   {     cacheLock.EnterReadLock();     try     {       return innerCache[key];     }     finally     {       cacheLock.ExitReadLock();     }   }    public void Add(int key, string value)   {     cacheLock.EnterWriteLock();     try     {       innerCache.Add(key, value);     }     finally     {       cacheLock.ExitWriteLock();     }   } ... 

which closely parallels explicit use of Monitor. With a little help from MS it could be as clean and simple as this.

private Dictionary<int, string> innerCache = new Dictionary<int, string>();  public string Read(int key) {   readlock(innerCache) return innerCache[key]; } public void Add(int key, string value) {   writelock (innerCache) innerCache.Add(key, value); } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:41:58+00:00Added an answer on May 11, 2026 at 11:41 am

    Take a look at ReaderWriterLockSlim class (or its older version, ReaderWriterLock). This lock class distinguishes between read and write locks, allowing you to have multiple readers but only a single writer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use any other DBMS that is not Microsoft Access to
Is there any performance difference between dbms_lob.instr and contains or am I doing something
I need to know if there is any embedded DBMS (preferably in Java and
I am using db4o as DBMS and I have a question: Is there any
Is there any subprogram similar to DBMS_METADATA.GET_DDL that can actually export the table data
Any suggestions on why a VB6 program would be slower when compiled than when
any suggestions for a C# object pooling framework? requirements are multi-thread support and a
Any astronomers out there? I'm wondering if anyone has produced or stumbled upon a
Any suggestions on how I can cleanup the following code pattern that repeats multiple
Any style for input affects every input element. Is there a way to specify

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.