1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

sync/waitgroup: force sleeping for 1ms

fixes issues #2874 and #2961
This commit is contained in:
Delyan Angelov 2019-12-03 14:05:08 +02:00 committed by Alexander Medvednikov
parent 0a8d2d5dc7
commit b907cf2179
2 changed files with 8 additions and 3 deletions

View File

@ -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)

View File

@ -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)
}
}
}