daily pastebin goal
22%
SHARE
TWEET

go_is_tricky.go

a guest Jun 4th, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top