golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.01k stars 17.54k forks source link

x/time/rate: document that the rate limiter is safe for concurrent usage #17261

Closed nightlyone closed 10 months ago

nightlyone commented 7 years ago

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.1 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/ingo/sources/go" GORACE="" GOROOT="/usr/local/go" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build059178747=/tmp/go-build -gno-record-gcc-switches" CXX="g++" CGO_ENABLED="1"

What did you do?

Read documentation of https://godoc.org/golang.org/x/time/rate

What did you expect to see?

Mention that all types (or at least which types, functions, methods) are safe for concurrent usage and don't need extra locking around them.

What did you see instead?

Nothing. But I concluded that by reading the code.

nightlyone commented 7 years ago

I only filed that issue, because I wanted to refer a colleague to the docs saying that this needs no extra locks, but found that the docs don't mention it and Go documentation style default is "you need locking until stuff is marked as concurrency safe".

cz2h commented 2 years ago

Can I work on this issue ? I would like to implement a couple test cases for functions like Limit(), SetLimit() ... for type Limiter. Currently there is only one test case for method Allow() that uses multi goroutines. @ALTree @bradfitz

ianlancetaylor commented 2 years ago

@zengchu2 Go ahead. Thanks.

cz2h commented 2 years ago

@zengchu2 Go ahead. Thanks.

Suggested implementation has been submitted on Gerrit (#416374). Any comments and suggestions are appreciated :)

gopherbot commented 1 year ago

Change https://go.dev/cl/496536 mentions this issue: rate: document safety for concurrent use

gopherbot commented 12 months ago

Change https://go.dev/cl/530855 mentions this issue: rate: add documentation on Limiter concurrent usage