Reputation: 4286
Just to make sure, say that i have this code:
this.allObjects = [some linq query];
and have two methods that both read (not modify) this IEnumerable, are they safe to call in parallel? Just looping through a IEnumerable should be safe right?
Upvotes: 0
Views: 203
Reputation: 110111
The IEnumerable<T>
instances are probably fine (although it does depend on implementation).
IEnumerator<T>
instances are probably not fine (although again: implementation details).
Upvotes: 0
Reputation: 10776
It depends on the implementation of the Enumerator, but in most cases, yes, it is safe.
One note though: the pseudocode, as you have it, doesn't actually do anything (due to deferred execution). The LINQ query will only execute when you access allObjects
(or if you call something like ToList()
on the LINQ query).
Upvotes: 1