Home > Blockchain >  Is false sharing the case with heap memory?
Is false sharing the case with heap memory?

Time:06-01

As I know, false sharing occurs when several threads try to read small and adjacent pieces of data which are placed within the same cache line:

#include <omp.h>
#define NUM_THREADS 4

int main() {
    int arr[NUM_THREADS];

#   pragma omp parallel num_threads(NUM_THREADS)
    {
        const int id = omp_get_thread_num();
        arr[id] // doing something with it
    }
}

What if I create the array dynamically?

int *arr = new int[NUM_THREADS];

Will false sharing take place if I have my array on the heap? Are there some cache line restrictions in this case?

CodePudding user response:

Memory is memory. To the cpu an array on the stack is exactly the same as an array on the heap. So any false sharing problem remains the same.

  • Related