Skip to content

Instantly share code, notes, and snippets.

@jeffprestes
Created November 19, 2017 13:50
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 jeffprestes/3ccb8db9a9dd3930889aa50f047d1751 to your computer and use it in GitHub Desktop.
Save jeffprestes/3ccb8db9a9dd3930889aa50f047d1751 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"runtime"
)
func waitForIt() {
ch := make(chan bool)
<-ch
}
func cpuIntensive(p *int, done chan bool) {
for i := 1; i < 100000000000; i++ {
go waitForIt()
}
done <- true
}
func main() {
// trace.Start(os.Stderr)
// defer trace.Stop()
runtime.GOMAXPROCS(1)
x := 0
done := make(chan bool)
go cpuIntensive(&x, done)
runtime.Gosched()
// printed only after cpuIntensive is completely finished
fmt.Println("terminou ", x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment