mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2026-05-22 05:46:30 +03:00
first code/readme/license commit
This commit is contained in:
22
misc/tests/atomic-toy.go
Normal file
22
misc/tests/atomic-toy.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import "time"
|
||||
import "sync/atomic"
|
||||
import "runtime"
|
||||
|
||||
func main() {
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user