标签:amp .com cond href func hub == add atomic
package main
import (
"fmt"
"sync/atomic"
"time"
)
func main() {
var count uint32
trigger := func(i uint32, fn func()) {
for {
if n := atomic.LoadUint32(&count); n == i {
fn()
atomic.AddUint32(&count, 1)
break
}
time.Sleep(time.Nanosecond)
}
}
for i := uint32(0); i < 10; i++ {
go func(i uint32) {
fn := func() {
fmt.Println(i)
}
trigger(i, fn)
}(i)
}
trigger(10, func() {})
}
标签:amp .com cond href func hub == add atomic
原文地址:https://www.cnblogs.com/linyihai/p/10242115.html