package main
import (
"fmt"
_ "net/http/pprof"
"runtime"
"sync"
"time"
)
const size = 1000000
func alloc(n int) {
fmt.Printf("alloc %v, before alloc\n", n)
_ = make([]int, size, size)
fmt.Printf("alloc %v, after alloc\n", n)
}
var wg sync.WaitGroup
func main() {
cpunum := runtime.NumCPU()
runtime.GOMAXPROCS(cpunum)
alloc(1)
wg.Add(1)
go func() {
fmt.Printf("in go func\n")
defer wg.Done()
for true {
}
}()
time.Sleep(time.Second)
alloc(2)
wg.Wait()
}
run this code on my linux machine, which has 4 CPU.
Only output the following message, then hanging:
alloc 1, before alloc
alloc 1, after alloc
in go func
alloc 2, before alloc
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.