There is no reason to do this, and it's more work.
««« original CL description
net: make channel-based semaphore depend on receive, not send
R=r, dvyukov
CC=golang-dev
https://golang.org/cl/
13348045
»»»
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/
13632047
var threadLimit = make(chan struct{}, 500)
-func init() {
- for i := 0; i < cap(threadLimit); i++ {
- threadLimit <- struct{}{}
- }
-}
+// Using send for acquire is fine here because we are not using this
+// to protect any memory. All we care about is the number of goroutines
+// making calls at a time.
func acquireThread() {
- <-threadLimit
+ threadLimit <- struct{}{}
}
func releaseThread() {
- threadLimit <- struct{}{}
+ <-threadLimit
}