But i have 4 os threads to schedule the goroutines, there are spare CPU to 
run the main goroutine.

On Thursday, March 2, 2017 at 12:50:35 PM UTC+8, Henry wrote:
>
> Hi,
>
> The processing power for your second allocation is consumed by your 
> goroutine. There is an endless loop in your goroutine. Eventually, when 
> there is enough juice, your second allocation will be called.
>
> On Thursday, March 2, 2017 at 11:07:08 AM UTC+7, Kai Zhang wrote:
>
>> 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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to