diff options
Diffstat (limited to 'tests/benchmarks/increment-mutex/stm.go')
-rw-r--r-- | tests/benchmarks/increment-mutex/stm.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/benchmarks/increment-mutex/stm.go b/tests/benchmarks/increment-mutex/stm.go new file mode 100644 index 0000000..9a442a5 --- /dev/null +++ b/tests/benchmarks/increment-mutex/stm.go @@ -0,0 +1,43 @@ +package stm + +import ( + "flag" + "sync" +) + + + +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++ { + v := 0 + var mu sync.Mutex + for i := 0; i < 1000; i++ { + go func() { + mu.Lock() + defer mu.Unlock() + v++ + }() + } + + for { + var read int + func() { + mu.Lock() + defer mu.Unlock() + read = v + }() + if read == 1000 { + break + } + } + } +} |