Last active
April 9, 2020 13:15
-
-
Save pot-code/9b748eda0e42688d0502765ed867774d to your computer and use it in GitHub Desktop.
[goroutine] snippet
This file contains 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
func worker(queue chan string, signal *sync.WaitGroup) { | |
for work := range queue { | |
} | |
signal.Done() | |
} | |
func main() { | |
count := runtime.NumCPU() - 1 | |
queue := make(chan string, 10) | |
signal := new(sync.WaitGroup) | |
signal.Add(count) | |
for i := 0; i < count; i++ { | |
go worker(queue, signal) | |
} | |
// | |
// fill queue | |
// | |
close(queue) | |
signal.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment