projekt pk_os_go
This commit is contained in:
parent
5577560640
commit
decc8f3324
16 changed files with 70 additions and 126 deletions
47
pk_os_go/g4.go
Normal file
47
pk_os_go/g4.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/trace"
|
||||
"time"
|
||||
debug "runtime/debug"
|
||||
)
|
||||
|
||||
func child(c chan string) {
|
||||
for msg := range c {
|
||||
c <- msg
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
f, err := os.Create("trace.out")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if err := trace.Start(f); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer trace.Stop()
|
||||
|
||||
runtime.GOMAXPROCS(1)
|
||||
debug.SetGCPercent(-1)
|
||||
|
||||
c := make(chan string)
|
||||
go child(c)
|
||||
|
||||
const niters = 2000000
|
||||
for i := 0; i < niters; i++ {
|
||||
c <- "test"
|
||||
reply := <-c
|
||||
if len(reply) != 4 {
|
||||
panic("err")
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("done")
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue