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 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

I have found some evidence that this is possible, self.scene = Canvas() Application.LoadComponent(self.scene, Uri('app.xaml',
I have looked on FaceBook Developer page and found that it's possible to create
I have found that my HTML is, to be honest, very clunky. Small, simple
Is this even possible without calling a specific package? I have found countless examples
I have found no way to translate a simple select like SELECT * FROM
I've searched all over and have found possible solutions but they don't quite work
I have found articles saying this is possible, but what are the issues? Is
Possible Duplicates: Undefined Behavior and Sequence Points Order of function call I have found
I have found this great tutorial, about uploading files with a Flex app, using
I have found that development for Symbian is possible in C++ with Qt, but

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.