v2 / vlib / v / tests / concurrency / atomic_test.v
22 lines · 18 sloc · 274 bytes · 99be39cbd15d4bbb5ab14d2f870199908c00bc8d
Raw
1import time
2
3// vtest retry: 3
4
5struct App {
6mut:
7 idx atomic int
8}
9
10fn test_atomic() {
11 mut app := &App{}
12 for i in 0 .. 10 {
13 spawn app.run()
14 }
15 time.sleep(200 * time.millisecond)
16 println('idx=${app.idx}')
17 assert app.idx == 10
18}
19
20fn (mut app App) run() {
21 app.idx++
22}
23