What happens if thread_id gets reused?
Scenario:
- Segment stores the thread_id it was created in.
- The thread is no longer available, but the segment stays still keeping it's number.
- After really long time, the thread_id gets reused, and as it happens the current thread has this number and wants to free object from the segment above (with the same thread_id)?
Does mimalloc handle this case gracefully?
Hi @malkia -- ah, no worries -- this is handled well. In particular, when a thread terminates the _mi_thread_done is called which will "abandon" all segments and set their thread-id to 0 (and preventing reused thread-id issues). Btw. we need to keep the segments alive since they contain still live data resulting from pointers that are shared with other threads). Later, other threads can "reclaim" such abandoned segments (see _mi_segment_try_reclaim) and reuse the memory that was abandoned.
Awesome - thank you so much! This makes it for another re-reading of the source code! Much appreciated!