GO并发,采用CSP模型(Communication Sequantial Process)
1,csp模型
2,不需要锁、不需要callback
3,并发编程
1,性能保障,可以做系统开发
2,垃圾回收机制
3,灵活的类型、支持函数式编程、异步IO
4,并发处理
package main
import "net/http"
import "fmt"
func main() {
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
fmt.Fprintln(writer, "<h1>Hello world</h1>")
})
http.ListenAndServe(":8888", nil)
}
package main
import (
"fmt"
)
func main(){
ch := make(chan string)
for i := 0;i <5;i++{
go printHelloWorld(i,ch)
}
for{
msg:=<- ch
fmt.Println(msg)
}
}
func printHelloWorld(i int, ch chan string){
for{
ch <- fmt.Sprintf("Hello World from goroutine %d\n",i)
}
}
有疑问加站长微信联系(非本文作者)