If I have something like this (pseudocode):
class A
{
List<SomeClass> list;
private void clearList()
{
list = new List<SomeClass>();
}
private void addElement()
{
list.Add(new SomeClass(...));
}
}
is it possible that I run into multithreading problems (or any kind of unexpected behavior) when both functions are executed in parallel?
The use case is a list of errors, which could be cleared at any time (by simply assigning a new, empty list).
EDIT: My assumptions are
- only one thread adds elements
- forgotten elements are okay (i.e. race condition between clearing and adding a new element), as long as the clear operation succeeds without problems
- .NET 2.0