crystal
crystal copied to clipboard
Fix: GC safety in Thread#start
Follow up to #14554 where a comment by @yxhuvud made me realize that Thread#start wasn't exactly GC safe, in that a GC collection could happen in parallel to a thread starting and it could free the Thread object before the thread is started or before the thread is properly shutdown.
The patch mostly moves the calls to add/remove the thread object from the linked list, along with some explanations.
Note: only the last commit is relevant, the rest is from #14554.
Interestingly that caused CI to segfault with -Dpreview_mt :raised_eyebrow:
Of course, no stacktrace and I can't reproduce.