* johnmr...@gmail.com <johnmr...@gmail.com> [190131 23:50]: > > Writing to adjacent memory locations [i.e. different array elements, from > > different goroutines] will cause false sharing between CPU caches. This is > > a performance, not a correctness issue. > > I'm looking to make an array of thread-safe counters - each counting a > different thing. I propose to use an ordinary array, of fixed size, with > thread safety coming solely from use of atomic operations to increment the > values. Will it be correct, but prone to false sharing between caches?
Your method sounds like it will be correct. If a single array element is only ever accessed from a single goroutine, then the atomic operations will not be necessary, and whether you use atomics or not, there will be false cache sharing. If a single array element is ever accessed by more than one goroutine, then the atomics are necessary, and there will be necessary cache sharing. ...Marvin -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.