Go 语言并发编程之美

Go 并发编程

Go 语言的 goroutine 和 channel 让并发编程变得简单而优雅。

Goroutine

go func() {
    fmt.Println("Hello from goroutine")
}()

Channel

ch := make(chan int, 1)
ch <- 42
fmt.Println(<-ch)

Go 的并发哲学是:不要通过共享内存来通信,而要通过通信来共享内存。

评论 (0)

登录后发表评论