Advertisement
Guest User

go_is_tricky.go

a guest
Jun 4th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.40 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "time"
  6. )
  7.  
  8. func doNothing() {
  9.     for {
  10.     }
  11. }
  12.  
  13. func doSomething() {
  14.     for i := 0; i < 10; i++ {
  15.         time.Sleep(time.Millisecond * 5)
  16.         fmt.Printf("%d ms\n", i)
  17.     }
  18. }
  19.  
  20. func main() {
  21.     for i := 0; i < 10; i++ {
  22.         go doNothing()
  23.     }
  24.  
  25.     doSomething()
  26.  
  27.     // What's the output of this code in the 5s duration?
  28.     // What's the output when line 15 is commented out?
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement