I'm developing a data aggregation object on a multi-thread environment, and I have the following situation:
int counts;
// This event is triggered by many threads at the same time
public void OnDataReceived(DataEvent evt)
{
counts += evt.counts;
}
My question is whether it is safe to do
counts += evt.counts;
or I need something like
lock(lockObject)
{
counts += evt.counts;
}