crystal icon indicating copy to clipboard operation
crystal copied to clipboard

Fix: GC safety in Thread#start

Open ysbaddaden opened this issue 1 year ago • 1 comments

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.

ysbaddaden avatar May 03 '24 14:05 ysbaddaden

Interestingly that caused CI to segfault with -Dpreview_mt :raised_eyebrow:

Of course, no stacktrace and I can't reproduce.

ysbaddaden avatar May 03 '24 15:05 ysbaddaden