摘要: 1. Go语言中可以使用sync.WaitGroup来实现并发任务的同步 package main import ( "fmt" "sync" ) func hello(wg *sync.WaitGroup) { defer wg.Done() fmt.Println("hello") } func 阅读全文
posted @ 2021-11-08 17:37 专职 阅读(627) 评论(0) 推荐(0) 编辑
摘要: 1. 并发安全 package main import ( "fmt" "sync" ) var ( sum int wg sync.WaitGroup ) func test() { for i := 0; i < 5000000; i++ { sum += 1 } wg.Done() } fun 阅读全文
posted @ 2021-11-08 14:35 专职 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 1. timer 定时器,时间到了执行,只执行一次 package main import ( "fmt" "time" ) func main() { // 1. timer基本使用 /* timer1 := time.NewTimer(2 * time.Second) t := time.Now 阅读全文
posted @ 2021-11-08 11:07 专职 阅读(428) 评论(0) 推荐(0) 编辑