mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-07-06 19:38:41 +03:00
merge from dev
This commit is contained in:
commit
e3744fa3fe
6 changed files with 170 additions and 91 deletions
|
@ -3,9 +3,13 @@
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <new>
|
||||
#include <vector>
|
||||
#include <future>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#include <mimalloc.h>
|
||||
#include <mimalloc-new-delete.h>
|
||||
#include <mimalloc-override.h>
|
||||
|
@ -23,14 +27,16 @@ void heap_no_delete(); // issue #202
|
|||
void heap_late_free(); // issue #204
|
||||
void padding_shrink(); // issue #209
|
||||
void various_tests();
|
||||
void test_mt_shutdown();
|
||||
|
||||
int main() {
|
||||
mi_stats_reset(); // ignore earlier allocations
|
||||
heap_thread_free_large();
|
||||
heap_no_delete();
|
||||
heap_late_free();
|
||||
padding_shrink();
|
||||
heap_no_delete();
|
||||
heap_late_free();
|
||||
padding_shrink();
|
||||
various_tests();
|
||||
//test_mt_shutdown();
|
||||
mi_stats_print(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
@ -133,7 +139,7 @@ bool test_stl_allocator2() {
|
|||
// Issue #202
|
||||
static void heap_no_delete_worker() {
|
||||
mi_heap_t* heap = mi_heap_new();
|
||||
void* q = mi_heap_malloc(heap,1024);
|
||||
void* q = mi_heap_malloc(heap, 1024);
|
||||
// mi_heap_delete(heap); // uncomment to prevent assertion
|
||||
}
|
||||
|
||||
|
@ -189,3 +195,29 @@ void heap_thread_free_large() {
|
|||
t1.join();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_mt_shutdown()
|
||||
{
|
||||
const int threads = 5;
|
||||
std::vector< std::future< std::vector< char* > > > ts;
|
||||
|
||||
auto fn = [&]()
|
||||
{
|
||||
std::vector< char* > ps;
|
||||
ps.reserve(1000);
|
||||
for (int i = 0; i < 1000; i++)
|
||||
ps.emplace_back(new char[1]);
|
||||
return ps;
|
||||
};
|
||||
|
||||
for (int i = 0; i < threads; i++)
|
||||
ts.emplace_back(std::async(std::launch::async, fn));
|
||||
|
||||
for (auto& f : ts)
|
||||
for (auto& p : f.get())
|
||||
delete[] p;
|
||||
|
||||
std::cout << "done" << std::endl;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue