In this false sharing test at github, an array is define as int array[100]
. And it says
bad_index = 1
good_index = 99
. Then it creates two threads and does the following:
- False sharing: thread_1 updates
A[0]
, thread_2 updatesA[bad_index]
- No false sharing: thread_1 updates
A[0]
, thread_2 updatesA[good_index]
With false sharing, the operation slower more than 2x. And my question is why index 1
is bad and index 99
is good?