Skip to content

Instantly share code, notes, and snippets.

@yuzhouu
Last active July 29, 2018 06:18
Show Gist options
  • Save yuzhouu/4e4003b21416afada25220e64a8fd717 to your computer and use it in GitHub Desktop.
Save yuzhouu/4e4003b21416afada25220e64a8fd717 to your computer and use it in GitHub Desktop.
go thread limit from net.go
var threadLimit chan struct{}
var threadOnce sync.Once
func acquireThread() {
threadOnce.Do(func() {
threadLimit = make(chan struct{}, concurrentThreadsLimit())
})
threadLimit <- struct{}{}
}
func releaseThread() {
<-threadLimit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment