[Mono-list] Thread safe list in C#
jonpryor at vt.edu
Mon Sep 10 18:38:31 UTC 2012
On Sep 3, 2012, at 1:31 AM, vnan122 <veereshamc at gmail.com> wrote:
> Hello every one, I just want to know how to make a list thread safe
In practice, you don't; a method can do anything...
By convention, you can generally assume that static members are thread safe and instance members are not (unless those instance methods are exposed from static methods, e.g. System.Reflection), but that's by no means guaranteed and may be violated.
In general, you need to read the documentation to determine which members are threadsafe and which are not.
> and is there any options for concurrent list like in JAVA.
Have you tried System.Collections.Concurrent.ConcurrentBag<T>?
This assumes that you don't need to maintain ordering.
Of course, you could always just use List<T> + `lock`, unless/until profiling demonstrates that you're spending too much time acquiring locks...
More information about the Mono-list