We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go version
$ go version go version go1.19 linux/amd64
Yes
go env
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/ccssrryy.cache/go-build" GOENV="/home/ccssrryy/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/ccssrryy/go/pkg/mod" GOOS="linux" GOPATH="/home/ccssrryygo" GOROOT="/home/ccssrryy/sdk/go1.19" GOSUMDB="sum.golang.google.cn" GOTMPDIR="" GOTOOLDIR="/home/ccssrryy/sdk/go1.19/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.19" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/tmp/std/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build125839981=/tmp/go-build -gno-record-gcc-switches"
package main import ( "log" "sync" "sync/atomic" "time" "golang.org/x/time/rate" ) func main() { var limitCount = 1000 var count int32 threads := 200 stdLimiter := rate.NewLimiter(rate.Limit(limitCount), limitCount) var wg sync.WaitGroup startgs := func(threads int) { start := time.Now() for i := 0; i < threads; i++ { go func() { defer wg.Done() for { if time.Since(start) > time.Second { return } if stdLimiter.Allow() { atomic.AddInt32(&count, 1) } } }() } } wg.Add(threads) startgs(threads) wg.Wait() if atomic.LoadInt32(&count) > int32(3*limitCount) { log.Fatalf("fail, unexpected count: %d \n", count) } else { log.Println("success") } }
success
fail, unexpected count: 115876
Allow() is getting current time out of the mu lock.
Allow()
The text was updated successfully, but these errors were encountered:
Duplicate of #45245
Sorry, something went wrong.
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
success
What did you see instead?
fail, unexpected count: 115876
Why
Allow()
is getting current time out of the mu lock.The text was updated successfully, but these errors were encountered: