标签:资源 nis runtime ima 语言 div syn group alt
下一步应该是互斥锁了。
package main import ( "fmt" "runtime" "sync" "sync/atomic" ) var ( counter int64 wg sync.WaitGroup ) func main() { wg.Add(2) fmt.Println("Create Goroutines") go incCounter(1) go incCounter(2) fmt.Println("Waiting To Finish") wg.Wait() fmt.Println("Final Counter:", counter) } func incCounter(id int) { defer wg.Done() for count := 0; count < 2; count++ { atomic.AddInt64(&counter, 1) runtime.Gosched() } }
标签:资源 nis runtime ima 语言 div syn group alt
原文地址:http://www.cnblogs.com/aguncn/p/7099050.html