Just ran into a program where += is used on a shared variable among threads, so is += thread safe, i.e. performs addition and assignment atomically?
No it isn't thread safe since it's equivalent to:
int temp = orig + value; orig = temp;
You can use Interlocked.Add instead:
Interlocked.Add
Interlocked.Add(ref orig, value);
2.1m questions
2.1m answers
60 comments
57.0k users