看go程序:

package main
import "fmt"
import "time"

func main(){
    go f()
    
    a := fib(45)  // very slow
    fmt.Println("main ends", a)
}

func fib(x int) int {
    if x < 2 {
        return x
    }

    return fib(x - 1) + fib(x - 2)
}

func f(){
    for {
        time.Sleep(time.Second)
        fmt.Println("slept")
    }
}

         结果:

ubuntu@VM-0-15-ubuntu:~/taoge/go$ ./test 
slept
slept
slept
slept
slept
slept
slept
slept
slept
main ends 1134903170
ubuntu@VM-0-15-ubuntu:~/taoge/go$ 

        自己感受。

 

 


本文转载:CSDN博客