Last active
July 29, 2018 06:18
-
-
Save yuzhouu/4e4003b21416afada25220e64a8fd717 to your computer and use it in GitHub Desktop.
go thread limit from net.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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