Skip to content

Instantly share code, notes, and snippets.

@gnsx
Created August 26, 2019 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnsx/6880bbfdf70cc33267b702ffa61e862a to your computer and use it in GitHub Desktop.
Save gnsx/6880bbfdf70cc33267b702ffa61e862a to your computer and use it in GitHub Desktop.
//Base example to use while multithreading in golang
package main
import (
"fmt"
)
func main() {
done := make(chan bool)
tasks := make(chan int64)
for worker := 0; worker < 4; worker++ {
go func(tasks chan int64, done chan bool) {
for ELement := range tasks {
fmt.Print("\n", ELement)
<-done
}
}(tasks, done)
}
for i := int64(0); i < 10; i++ {
tasks <- i
done <- true
}
close(tasks)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment