Created
March 20, 2019 21:15
-
-
Save kirugan/f572dfbefc630443bc606040d7d145e3 to your computer and use it in GitHub Desktop.
Go scheduler design migh lead your code to freeze
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
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