| 1 | // vtest build: tinyc && linux |
| 2 | // vtest vflags: -cc tcc -no-retry-compilation |
| 3 | module main |
| 4 | |
| 5 | struct Counter { |
| 6 | mut: |
| 7 | value atomic int |
| 8 | } |
| 9 | |
| 10 | fn (mut c Counter) add_many(n int) { |
| 11 | for _ in 0 .. n { |
| 12 | c.value++ |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | fn test_tcc_atomic_postfix_is_atomic() { |
| 17 | mut counter := &Counter{} |
| 18 | mut threads := []thread{cap: 8} |
| 19 | for _ in 0 .. 8 { |
| 20 | threads << spawn counter.add_many(200_000) |
| 21 | } |
| 22 | threads.wait() |
| 23 | assert counter.value == 1_600_000 |
| 24 | } |
| 25 |