5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 23:31:36 +00:00
yggdrasil-go/misc/tests/atomic-toy.go

23 lines
329 B
Go
Raw Normal View History

2017-12-29 04:16:20 +00:00
package main
import "fmt"
import "time"
import "sync/atomic"
import "runtime"
func main() {
2018-01-04 22:37:51 +00:00
var ops uint64 = 0
for i := 0; i < 4; i++ {
go func() {
for {
atomic.AddUint64(&ops, 1)
runtime.Gosched()
}
}()
}
time.Sleep(1 * time.Second)
opsFinal := atomic.LoadUint64(&ops)
fmt.Println("ops:", opsFinal)
2017-12-29 04:16:20 +00:00
}