-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
I was trying the new first class heaps (mimalloc 3.2.8, installed via vcpkg), but I encountered some issues.
I can reliably get the following error in debug mode:
assertion failed: at "alloc.c":136, mi_theap_malloc_small_zero_nonnull
assertion: "theap->tld->thread_id == 0 || theap->tld->thread_id == tid"
In release mode, a SIGSEGV is triggered.
My reproducer
#include <cassert>
#include <cstdlib>
#include <print>
#include <thread>
#include <vector>
#include <mimalloc.h>
#include <barrier>
using namespace std;
// We repeatedly
// * (Destroy previous heap)
// * Create a new heap
// * Allocate from the heap with threads
// This seems to trigger assertions or segfaults in mimalloc
int main()
{
int numWorkers = 32;
std::barrier startBar(numWorkers + 1);
std::barrier doneBar(numWorkers + 1);
vector<jthread> threads;
mi_heap_t* heap = nullptr;
for (int i = 0; i < numWorkers; i++)
{
threads.emplace_back([&startBar, &doneBar, &heap](std::stop_token tok)
{
while (true)
{
startBar.arrive_and_wait();
if (tok.stop_requested())
return;
mi_heap_t* localHeap = heap;
if (true)
{
for (int j = 0; j < 100; j++)
{
assert(localHeap);
auto* ptr = mi_heap_malloc(localHeap, 17);
mi_free(ptr);
}
}
doneBar.arrive_and_wait();
}
});
}
for (size_t j = 0; j < 100; j++)
{
std::print(stderr, "Round {}\n", j);
if (heap)
mi_heap_destroy(heap);
heap = mi_heap_new();
startBar.arrive_and_wait();
doneBar.arrive_and_wait();
}
for (auto& t : threads)
t.request_stop();
startBar.arrive_and_wait();
return 0;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels