-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
In a multithreaded environment we encountered a data race condition for the lazy init of theap (in heap.c line 52).
In our case this caused an access violation while reading memory.
Suggestion:
The [heap->theap]field should either be:
- atomic or
- protected by [heap->theaps_lock] or
- the init should be done in the mi_heap_new() factory.
The race is narrow but real in thread-pool scenarios where multiple threads start allocating from a shared heap simultaneously.
The issue can be circumvented by allocating some memory when the mi_heap is created. E.g.
m_mi_heap = mi_heap_new(); if (m_mi_heap) { // Force theap TLS key initialization on the creating thread // to avoid a race when workers first use this heap concurrently void* dummy = mi_heap_malloc(m_mi_heap, 1); mi_free(dummy); }
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels