Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created November 7, 2017 08:34
Show Gist options
  • Save kaityo256/c4fc64ffdd5a8725e0ed038bf09fe7bc to your computer and use it in GitHub Desktop.
Save kaityo256/c4fc64ffdd5a8725e0ed038bf09fe7bc to your computer and use it in GitHub Desktop.
malloc test on multithread
#include <cstdio>
#include <cstdlib>
#include <omp.h>
const int N = 16;
int
main(int argc, char **argv){
char *buf[N];
size_t size = atoi(argv[1]);
printf("digraph test_%d\n {\n",size);
#pragma omp parallel for
for(int i=0;i<N;i++) buf[i] = (char*)malloc(size);
#pragma omp parallel for
for(int i=0;i<N;i++){
for(int j=0;j<size;j++)buf[i][j] = 0;
}
#pragma omp barrier
for(int i=0;i<N;i++){
free(buf[i]);
size_t *p = (size_t*)(buf[i]);
printf("\"%lx\" -> \"%lx\"\n",(p-2),*p);
}
#pragma omp barrier
printf("}\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment