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