mirror of
https://github.com/vlang/v.git
synced 2025-08-05 18:57:45 -04:00
sync: use an atomic counter in test_waitgroup_go in waitgroup_test.v
This commit is contained in:
parent
9957327c37
commit
2c2ded2e0b
@ -1,6 +1,7 @@
|
|||||||
module sync
|
module sync
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import sync.stdatomic
|
||||||
|
|
||||||
fn test_waitgroup_reuse() {
|
fn test_waitgroup_reuse() {
|
||||||
mut wg := new_waitgroup()
|
mut wg := new_waitgroup()
|
||||||
@ -41,14 +42,13 @@ fn test_waitgroup_no_use() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_waitgroup_go() {
|
fn test_waitgroup_go() {
|
||||||
mut counter := 0
|
mut counter := stdatomic.new_atomic(0)
|
||||||
p := unsafe { &counter }
|
|
||||||
mut wg := new_waitgroup()
|
mut wg := new_waitgroup()
|
||||||
for i in 0 .. 10 {
|
for i in 0 .. 10 {
|
||||||
wg.go(fn [p] () {
|
wg.go(fn [mut counter] () {
|
||||||
unsafe { (*p)++ }
|
counter.add(1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
wg.wait()
|
wg.wait()
|
||||||
assert counter == 10
|
assert counter.load() == 10
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user