Skip to content

Commit 2f90e2b

Browse files
authored
Fix: new_thread spec helper must return isolated context (not thread) (#16421)
Tiny refactor to wait (join) on the isolated context, not its underlying thread. Preparation for thread pool where isolated threads might not terminate immediately. We thus can't join the thread and must wait on the isolated context/fiber instead.
1 parent 4e1fdc8 commit 2f90e2b

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

spec/std/fiber/execution_context/global_queue_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe Fiber::ExecutionContext::GlobalQueue do
100100
queue = Fiber::ExecutionContext::GlobalQueue.new(Thread::Mutex.new)
101101
ready = Thread::WaitGroup.new(n)
102102

103-
threads = Array(Thread).new(n) do |i|
103+
threads = Array.new(n) do |i|
104104
new_thread("ONE-#{i}") do
105105
slept = 0
106106
ready.done
@@ -147,7 +147,7 @@ describe Fiber::ExecutionContext::GlobalQueue do
147147
queue = Fiber::ExecutionContext::GlobalQueue.new(Thread::Mutex.new)
148148
ready = Thread::WaitGroup.new(n)
149149

150-
threads = Array(Thread).new(n) do |i|
150+
threads = Array.new(n) do |i|
151151
new_thread("BULK-#{i}") do
152152
slept = 0
153153

spec/std/fiber/execution_context/runnables_spec.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ describe Fiber::ExecutionContext::Runnables do
222222
Fiber::ExecutionContext::Runnables(16).new(global_queue)
223223
end
224224

225-
threads = Array(Thread).new(n) do |i|
225+
threads = Array.new(n) do |i|
226226
new_thread("RUN-#{i}") do
227227
runnables = all_runnables[i]
228228
slept = 0
@@ -277,7 +277,7 @@ describe Fiber::ExecutionContext::Runnables do
277277
Thread.sleep(10.nanoseconds) if i % 2 == 1
278278
end
279279

280-
threads.map(&.join)
280+
threads.each(&.join)
281281

282282
# must have dequeued each fiber exactly X times (no less, no more)
283283
fibers.each { |fc| fc.counter.should eq(increments) }

spec/support/thread.cr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{% begin %}
2-
def new_thread(name = nil, &block) : Thread
2+
def new_thread(name = nil, &block)
33
{% if flag?(:execution_context) %}
4-
ctx = Fiber::ExecutionContext::Isolated.new(name: name || "SPEC") { block.call }
5-
ctx.@thread
4+
Fiber::ExecutionContext::Isolated.new(name: name || "SPEC") { block.call }
65
{% else %}
76
Thread.new(name) { block.call }
87
{% end %}

0 commit comments

Comments
 (0)