aboutsummaryrefslogtreecommitdiff
path: root/tests/benchmarks/wait-n-no-delay/stm.go
blob: 97cac9acc5170a80808100976c2f225076ea5719 (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
package stm

import (
	"context"
	"flag"
	"sync"
)



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

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

	var wg sync.WaitGroup
	wg.Add(n)
	lim := NewLimiter(Limit(n), n)
	ctx := context.Background()
	for i := 0; i < n; i++ {
		go func() {
			lim.WaitN(ctx, 1)
			wg.Done()
		}()
	}
	wg.Wait()
}