mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
sync: use an atomic counter in test_waitgroup_go in waitgroup_test.v
This commit is contained in:
parent
9957327c37
commit
2c2ded2e0b
1 changed files with 5 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
module sync
|
||||
|
||||
import time
|
||||
import sync.stdatomic
|
||||
|
||||
fn test_waitgroup_reuse() {
|
||||
mut wg := new_waitgroup()
|
||||
|
@ -41,14 +42,13 @@ fn test_waitgroup_no_use() {
|
|||
}
|
||||
|
||||
fn test_waitgroup_go() {
|
||||
mut counter := 0
|
||||
p := unsafe { &counter }
|
||||
mut counter := stdatomic.new_atomic(0)
|
||||
mut wg := new_waitgroup()
|
||||
for i in 0 .. 10 {
|
||||
wg.go(fn [p] () {
|
||||
unsafe { (*p)++ }
|
||||
wg.go(fn [mut counter] () {
|
||||
counter.add(1)
|
||||
})
|
||||
}
|
||||
wg.wait()
|
||||
assert counter == 10
|
||||
assert counter.load() == 10
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue