1#include <thread>
2
3const size_t kAllocSize = 16;
4const size_t kInitialNumAllocs = 1 << 10;
5const size_t kPeriodicNumAllocs = 1 << 10;
6const size_t kNumIterations = 1 << 7;
7const size_t kNumThreads = 16;
8
9void Thread() {
10 char *InitialAllocations[kInitialNumAllocs];
11 char *PeriodicaAllocations[kPeriodicNumAllocs];
12 for (auto &p : InitialAllocations) p = new char[kAllocSize];
13 for (size_t i = 0; i < kNumIterations; i++) {
14 for (size_t j = 0; j < kPeriodicNumAllocs; j++) {
15 for (auto &p : PeriodicaAllocations) {
16 p = new char[kAllocSize];
17 *p = 0;
18 }
19 for (auto p : PeriodicaAllocations) delete [] p;
20 }
21 }
22 for (auto p : InitialAllocations) delete [] p;
23}
24
25int main() {
26 std::thread *Threads[kNumThreads];
27 for (auto &T : Threads) T = new std::thread(&Thread);
28 for (auto T : Threads) {
29 T->join();
30 delete T;
31 }
32}
33

source code of compiler-rt/lib/sanitizer_common/tests/malloc_stress_transfer_test.cpp