From b907cf21790b8ff5d2675f2859bcbdbf51ca5ec1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 3 Dec 2019 14:05:08 +0200 Subject: [PATCH] sync/waitgroup: force sleeping for 1ms fixes issues #2874 and #2961 --- examples/news_fetcher.v | 2 +- vlib/sync/waitgroup.v | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/news_fetcher.v b/examples/news_fetcher.v index dce80a2487..5b390a62ff 100644 --- a/examples/news_fetcher.v +++ b/examples/news_fetcher.v @@ -67,7 +67,7 @@ fn main() { wg := sync.new_waitgroup() mtx := sync.new_mutex() - mut fetcher := &Fetcher{ids: ids} + mut fetcher := &Fetcher{ids: ids mu: 0 wg: 0} fetcher.mu = &mtx fetcher.wg = &wg fetcher.wg.add(ids.len) diff --git a/vlib/sync/waitgroup.v b/vlib/sync/waitgroup.v index 307192e824..35a8f358a6 100644 --- a/vlib/sync/waitgroup.v +++ b/vlib/sync/waitgroup.v @@ -32,7 +32,12 @@ pub fn (wg mut WaitGroup) done() { pub fn (wg mut WaitGroup) wait() { for wg.active > 0 { - // waiting + // Do not remove this, busy empty loops are optimized + // with -prod by some compilers, see issue #2874 + $if windows { + C.Sleep(1) + } $else { + C.usleep(1000) + } } } -