From b3fd434ae07db5cf6385fb6b97a467e6f312c253 Mon Sep 17 00:00:00 2001 From: Robert Daniel Kortschak Date: Thu, 29 Aug 2013 17:14:57 +1000 Subject: [PATCH] net: make channel-based semaphore depend on receive, not send R=r, dvyukov CC=golang-dev https://golang.org/cl/13348045 --- src/pkg/net/net.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pkg/net/net.go b/src/pkg/net/net.go index c918e96b430..4f177c64edf 100644 --- a/src/pkg/net/net.go +++ b/src/pkg/net/net.go @@ -442,10 +442,16 @@ func (d *deadline) setTime(t time.Time) { var threadLimit = make(chan struct{}, 500) +func init() { + for i := 0; i < cap(threadLimit); i++ { + threadLimit <- struct{}{} + } +} + func acquireThread() { - threadLimit <- struct{}{} + <-threadLimit } func releaseThread() { - <-threadLimit + threadLimit <- struct{}{} }