1 | #include <thread> |
2 | |
3 | const size_t kAllocSize = 16; |
4 | const size_t kInitialNumAllocs = 1 << 10; |
5 | const size_t kPeriodicNumAllocs = 1 << 10; |
6 | const size_t kNumIterations = 1 << 7; |
7 | const size_t kNumThreads = 16; |
8 | |
9 | void 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 | |
25 | int 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 | |