| 1 | import time |
| 2 | |
| 3 | // vtest retry: 3 |
| 4 | |
| 5 | struct App { |
| 6 | mut: |
| 7 | idx atomic int |
| 8 | } |
| 9 | |
| 10 | fn 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 | |
| 20 | fn (mut app App) run() { |
| 21 | app.idx++ |
| 22 | } |
| 23 |