1 // RUN: %clangxx_asan -O0 %s -pthread -o %t && %run %t
2 // RUN: %clangxx_asan -O2 %s -pthread -o %t && %run %t
3 // REQUIRES: stable-runtime
7 #include <sanitizer/allocator_interface.h>
11 const size_t kLargeAlloc = 1UL << 20;
13 void* allocate(void *arg) {
14 volatile void *ptr = malloc(kLargeAlloc);
19 void* check_stats(void *arg) {
20 assert(__sanitizer_get_current_allocated_bytes() > 0);
25 size_t used_mem = __sanitizer_get_current_allocated_bytes();
26 printf("Before: %zu\n", used_mem);
27 const int kNumIterations = 1000;
28 for (int iter = 0; iter < kNumIterations; iter++) {
30 for (int j = 0; j < 4; j++) {
32 pthread_create(&thr[j], 0, (j < 2) ? allocate : check_stats, 0));
34 for (int j = 0; j < 4; j++)
35 assert(0 == pthread_join(thr[j], 0));
36 used_mem = __sanitizer_get_current_allocated_bytes();
37 if (used_mem > kLargeAlloc) {
38 printf("After iteration %d: %zu\n", iter, used_mem);
42 printf("Success after %d iterations\n", kNumIterations);