Skip to content

Instantly share code, notes, and snippets.

@kirugan
Created March 20, 2019 21:15
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 kirugan/f572dfbefc630443bc606040d7d145e3 to your computer and use it in GitHub Desktop.
Save kirugan/f572dfbefc630443bc606040d7d145e3 to your computer and use it in GitHub Desktop.
Go scheduler design migh lead your code to freeze
package main
import (
"fmt"
"runtime"
"sync"
"time"
)
func main() {
runtime.GOMAXPROCS(2)
var wg sync.WaitGroup
wg.Add(3)
go func() {
defer wg.Done()
var i int
for {
i++
}
}()
go func() {
defer wg.Done()
var i int
for {
i++
}
}()
time.Sleep(time.Second)
go func() {
defer wg.Done()
fmt.Println("Here I am!")
}()
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment