Skip to content

Commit

Permalink
Fix: Thread#current_fiber has been merged + crystal-lang/crystal#14558
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed May 6, 2024
1 parent c6cc8ce commit 1234db2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ jobs:
with:
crystal: nightly
id: crystal
- run: for f in patches/*; do cat $f | patch -d ${{ steps.crystal.outputs.path }} -p1; done
- run: crystal spec -Dpreview_mt spec/*_spec.cr -v
- run: crystal spec -Dpreview_mt -Dmt spec/*_spec.cr -v
18 changes: 0 additions & 18 deletions patches/crystal_gc.patch

This file was deleted.

25 changes: 15 additions & 10 deletions src/core_ext/thread.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ class Thread
# :nodoc:
property! current_scheduler : ExecutionContext::Scheduler

# :nodoc:
property! current_fiber : Fiber

def execution_context=(@execution_context : ExecutionContext)
main_fiber.execution_context = execution_context
end
Expand All @@ -24,18 +21,17 @@ class Thread
end
end

# the following methods set `@current_fiber` and are otherwise identical to crystal:master
# the following methods apply these patches:
# https://github.com/crystal-lang/crystal/pull/14558

def initialize
@func = ->(t : Thread) {}
@system_handle = Crystal::System::Thread.current_handle
@current_fiber = @main_fiber = Fiber.new(stack_address, self)
def initialize(@name : String? = nil, &@func : Thread ->)
@system_handle = uninitialized Crystal::System::Thread::Handle
init_handle

Thread.threads.push(self)
Thread.threads.push(self) # <= moved here
end

protected def start
Thread.threads.push(self)
Thread.current = self
@current_fiber = @main_fiber = fiber = Fiber.new(stack_address, self)

Expand All @@ -48,6 +44,15 @@ class Thread
rescue ex
@exception = ex
ensure
{% if flag?(:preview_mt) %}
# fix the thread stack now so we can start cleaning up references
GC.lock_read
GC.set_stackbottom(self, fiber.@stack_bottom)
GC.unlock_read
{% else %}
GC.set_stackbottom(fiber.@stack_bottom)
{% end %}

Thread.threads.delete(self)
Fiber.inactive(fiber)
detach { system_close }
Expand Down

0 comments on commit 1234db2

Please sign in to comment.