aboutsummaryrefslogtreecommitdiff
path: root/tests/benchmarks/increment-stm/stm.go
blob: 9f12eb17d48b2ab3b362a2ad8f3b8875be4eaea5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package stm

import (
	"flag"
)



var nFlag = flag.Int(
	"n",
	1_000,
	"The number of iterations to execute",
)

func MainTest() {
	flag.Parse()
	n := *nFlag

	for i := 0; i < n; i++ {
		// swap 1000 goroutines that each increment v by 1
		v := NewVar(0)
		for i := 0; i < 1000; i++ {
			go Atomically(VoidOperation(func(tx *Tx) {
				v.Set(tx, v.Get(tx) + 1)
			}))
		}

		// wait for v to reach 1000
		Atomically(VoidOperation(func(tx *Tx) {
			tx.Assert(v.Get(tx) == 1000)
		}))
	}
}