From 62226c2bb41bff21d608b503323f5628f19b5e16 Mon Sep 17 00:00:00 2001 From: Julien Portalier Date: Thu, 5 Sep 2024 10:56:57 +0200 Subject: [PATCH] Leverage WaitGroup#spawn --- src/compiler/crystal/compiler.cr | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/compiler/crystal/compiler.cr b/src/compiler/crystal/compiler.cr index 28adf6eb9fbf..ea1697743c1c 100644 --- a/src/compiler/crystal/compiler.cr +++ b/src/compiler/crystal/compiler.cr @@ -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