Is it OK to modify different histogram bins from different threads using `AddBinContent`?

If I don’t care about mean/stddev/entries consistency.

HI,
I don’t think is safe because two updates of the same bin can happen at the same time and then the result might not be correct. I would create an histogram for each thread or lock when calling the AddBinContent function (but will kill all performances)

Lorenzo

The sets of bins for each thread are not overlapping.

The playground for disaster is greater than the size of a bin content storage - it’s a cache line. But in practice we are aware of people doing what you say, and they survive :wink: But it’s risky, there’s no guarantee that the result is guaranteed to be correct. As Lorenzo said, you could use TThreadedObject https://root.cern/doc/master/classROOT_1_1TThreadedObject.html

I can random shuffle the bin numbers to the threads won’t content for a cache line.

is very slow.

TThreadedObject is much faster than locking a single histogram :slight_smile: It’s all relative…

I don’t understand the random shuffle comment - but that’s not needed for it to work! Glad you have a solution!