From 1d136a388272b8719613ab734237d239d5d30604 Mon Sep 17 00:00:00 2001 From: Juan Wajnerman Date: Tue, 17 Sep 2019 19:10:17 -0300 Subject: [PATCH] Fix corruption of thread linked list When a new thread finishes very quickly it could happen that the removal from the linked list was executed before the push. The linked list didn't check for that situation and it ends corrupted. --- src/thread.cr | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/thread.cr b/src/thread.cr index f2eeb6589e1f..700f03b0d593 100644 --- a/src/thread.cr +++ b/src/thread.cr @@ -34,9 +34,7 @@ class Thread Pointer(Void).null }, self.as(Void*)) - if ret == 0 - Thread.threads.push(self) - else + if ret != 0 raise Errno.new("pthread_create", ret) end end @@ -124,6 +122,7 @@ class Thread end protected def start + Thread.threads.push(self) Thread.current = self @main_fiber = fiber = Fiber.new(stack_address, self)