I'm considering an existing multi-threading C# application and noticed some code like
public abstract class Task
{
protected IList<string> action;
...
public void Initialize (params)
...
Several special "Tasks" derive from Task and some Task methods modify "action". So in my idea, this is not thread safe. Am I right ?
Thanks for any help,
Olivier
No, you are not right. action is an instance field, so each instance of the Task-derived class will have its own copy of action. It would potentially be a problem only if action were static.
To clarify, you can have many Task-derived objects. Each one of those will work just fine for a single thread. However, you do not want to have multiple threads accessing the same Task instance, unless the code that modifies action is protected with some kind of synchronization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With