Skip to content

Commit

Permalink
Fix corruption of thread linked list (crystal-lang#8196)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
waj authored and dnamsons committed Jan 10, 2020
1 parent e72d0c3 commit 2b40efd
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/thread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 2b40efd

Please sign in to comment.