Reputation: 33090
How do we know whether a method is thread safe or not
For example, if I check http://msdn.microsoft.com/en-us/library/3wcytfd1.aspx there is nothing that indicates its thread-safety.
Upvotes: 6
Views: 5628
Reputation: 39960
The documentation for the entire List<T>
class has a segment on thread safety:
Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Upvotes: 3
Reputation: 300579
No, they are not thread safe (without performing your own locking).
Use one of the Concurrent collections instead.
The System.Collections.Concurrent namespace provides several thread-safe collection classes that should be used in place of the corresponding types in the System.Collections and System.Collections.Generic namespaces whenever multiple threads are accessing the collection concurrently.
Upvotes: 10