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?

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.
As I understand it, you currently provide two immutability guarantees:
List<Bar>object.Bartype 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.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:
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.Concurrentnamespace. In particular, you may find theBlockingCollection<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.