Skip to content

Commit

Permalink
Leverage WaitGroup#spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed Sep 5, 2024
1 parent 96b6f77 commit 62226c2
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/compiler/crystal/compiler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -538,17 +538,15 @@ module Crystal

private def mt_codegen(units, n_threads)
channel = Channel(CompilationUnit).new(n_threads * 2)
wg = WaitGroup.new(n_threads)
wg = WaitGroup.new
mutex = Mutex.new

n_threads.times do
spawn do
wg.spawn do
while unit = channel.receive?
unit.compile(isolate_context: true)
mutex.synchronize { @progress_tracker.stage_progress += 1 }
end
ensure
wg.done
end
end

Expand Down

0 comments on commit 62226c2

Please sign in to comment.