Skip to content

Commit 25c7cfd

Browse files
authored
Merge pull request #3648 from byroot/fix-topgem-deadlock
2 parents 1f1d2b4 + 6e3c168 commit 25c7cfd

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

rakelib/lex.rake

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ module Prism
6262
def parallelize(items, &block)
6363
Thread.abort_on_exception = true
6464

65-
queue = Queue.new
66-
items.each { |item| queue << item }
65+
queue = Queue.new(items).close
6766

6867
workers =
69-
ENV.fetch("WORKERS") { 16 }.to_i.times.map do
68+
ENV.fetch("WORKERS", "16").to_i.times.map do
7069
parallelize_thread(queue, &block)
7170
end
7271

@@ -77,7 +76,11 @@ module Prism
7776

7877
# Create a new thread with a minimal number of locals that it can access.
7978
def parallelize_thread(queue, &block)
80-
Thread.new { block.call(queue.shift) until queue.empty? }
79+
Thread.new do
80+
while item = queue.pop
81+
block.call(item)
82+
end
83+
end
8184
end
8285
end
8386
end

0 commit comments

Comments
 (0)