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

  • SEARCH
  • Home
  • 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 431999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:01:51+00:00 2026-05-12T20:01:51+00:00

I have found possible slowdown in my app so I would have two questions:

  • 0

I have found possible slowdown in my app so I would have two questions:

  1. What is the real difference between simple locking on object and reader/writer locks?
    E.g. I have a collection of clients, that change quickly. For iterations should I use readerlock or the simple lock is enough?
  2. In order to decrease load, I have left iteration (only reading) of one collection without any locks. This collection changes often and quickly, but items are added and removed with writerlocks. Is it safe (I dont mind occassionally skipped item, this method runs in loop and its not critical) to left this reading unsecured by lock? I just dont want to have random exceptions.
  • 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. Editorial Team
    Editorial Team
    2026-05-12T20:01:51+00:00Added an answer on May 12, 2026 at 8:01 pm

    No, your current scenario is not safe.

    In particular, if a collection changes while you’re iterating over it, you’ll get an InvalidOperationException in the iterating thread. You should obtain a reader lock for the whole duration of your iterator:

    • Obtain reader lock
    • Iterate over collection
    • Release reader lock

    Note this is not the same as obtaining a reader lock for each step of the iteration – that won’t help.

    As for the difference between reader/writer locks and “normal” locks – the idea of a reader/writer lock is that multiple threads can read at the same time, but only one thread can write (and only when no-one is reading). In some cases this can improve performance – but it increases the complexity of the solution too (in terms of getting it right). I’d also advise you to use ReaderWriterLockSlim from .NET 3.5 if you possibly can – it’s much more efficient than the original ReaderWriterLock, and there are some inherent problems with ReaderWriterLock IIRC.

    Personally I normally use simple locks until I’ve proved that lock contention is a performance bottleneck. Have you profiled your application yet to find out where the bottleneck is?

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

Sidebar

Related Questions

Possible Duplicate: Difference between JOIN and INNER JOIN I have found some legacy SQL
I have found that it is possible to nest another property within an object
I have found SWTChart library and just wonder how it would be possible to
I have found some evidence that this is possible, self.scene = Canvas() Application.LoadComponent(self.scene, Uri('app.xaml',
I have to turn a org.w3c.dom.Document into a java.lang.String. I have found two possible
As the title say is it possible and how? I have found a .Find
I have found that it is impossible to write ( file_put_contents or simple fwrite
I have found already some similar discussion on this, but would like to investigate
Possible Duplicate: MySQL Injection - Use SELECT query to UPDATE/DELETE So I have found
Is this even possible without calling a specific package? I have found countless examples

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.