Playing with goroutines

This commit is contained in:
Mihalis Tsoukalos 2019-04-02 19:49:47 +03:00
commit ef65fe99ee
2 changed files with 36 additions and 0 deletions

17
ch10/cloGoCorrect.go Normal file
View file

@ -0,0 +1,17 @@
package main
import (
"fmt"
"time"
)
func main() {
for i := 0; i <= 20; i++ {
i := i
go func() {
fmt.Print(i, " ")
}()
}
time.Sleep(time.Second)
fmt.Println()
}

19
ch10/endlessComp.go Normal file
View file

@ -0,0 +1,19 @@
package main
import (
"fmt"
"runtime"
)
func main() {
var i byte
go func() {
for i = 0; i <= 255; i++ {
}
}()
fmt.Println("Leaving goroutine!")
runtime.Gosched()
runtime.GC()
fmt.Println("Good bye!")
}