Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions rakelib/lex.rake
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ module Prism
def parallelize(items, &block)
Thread.abort_on_exception = true

queue = Queue.new
items.each { |item| queue << item }
queue = Queue.new(items).close

workers =
ENV.fetch("WORKERS") { 16 }.to_i.times.map do
ENV.fetch("WORKERS", "16").to_i.times.map do
parallelize_thread(queue, &block)
end

Expand All @@ -77,7 +76,11 @@ module Prism

# Create a new thread with a minimal number of locals that it can access.
def parallelize_thread(queue, &block)
Thread.new { block.call(queue.shift) until queue.empty? }
Thread.new do
while item = queue.pop
block.call(item)
end
end
end
end
end
Expand Down
Loading