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 3598792
In Process

The Archive Base Latest Questions

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

I have a list of objects which will be accessible by many objects across

  • 0

I have a list of objects which will be accessible by many objects across many threads. To ensure thread safety I have made the list and its object read-only. My only concern is the iterators of the List<> object because I remember reading something about iterator thread safety issues. Do I have a problem?

alt text

For clarification: in the BarObservable class, the List < Bar > bar is read-only. The individual bars of the list are also read-only. The MarketDataAdaptor class uses BarService to add new bars to BarsObservable class. The diagram doesn’t show this but the IBarObservers are passed a reference to the List < Bar > . They can’t write to it but they do use the iterator of the List. Meanwhile the final bar is updated and once finalized a new bar is added to the end of the list.

  • 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-18T20:17:12+00:00Added an answer on May 18, 2026 at 8:17 pm

    As I understand it, you currently provide two immutability guarantees:

    1. There is an unchanging reference(s) to a List<Bar> object.
    2. The Bar type itself is immutable or is, by convention, instances of it are not mutated after they are added to the list.

    Neither of these is sufficient to deal with any concurrent reader / writer scenarios since the List<T> type itself is not thread-safe.

    1. If you have multiple unsynchronized writers, you could corrupt the list.
    2. If you have a single writer, with reader(s) on other threads, you probably won’t corrupt the list. On the other hand, the readers won’t work correctly. If you’re lucky, iterating the list in the middle of a write will throw a “Collection changed during enumeration” exception. If you’re not, your program will silently lose its functional correctness.

    Now you could try synchronizing access to the list with locks, ReaderWriterLockSlims, etc. How you do this will be specific to the Producer / Consumer relationships of your particular situation. For example, you could lock mutation during enumeration by either of these:

    1. Hold up an attempt to mutate as long as there is an active undisposed enumerator.
    2. Every time an enumerator is requested, block writers. Copy the list to another list; return its enumerator, and then unblock writers.

    But I would suggest, if you are on .NET 4.0, to take a look at the thread-safe collection classes in the System.Collections.Concurrent namespace. In particular, you may find the BlockingCollection<T> class to be exactly what you need.

    Finally, I would look at the overall design to see if you can solve this problem in a lock-free manner.

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

Sidebar

Related Questions

I have a list of objects which will be accessible by many objects across
I have an Object X which contains a list of Objects X. I do
I have a class which will store a list of objects and will also
I have a list which will store Number objects. The list will be populated
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the
I have a list of objects which I store in the session. This list
I have a list of objects which I want to turn into a set.
I have a list of objects which needs to be persisted in a SQL
I have a List of objects which are ordered. I would like to remove
I have a list of person objects which I want to send in response

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.