Why is this Go code blocking?

后端 未结 3 1444
旧巷少年郎
旧巷少年郎 2020-12-05 12:04

I wrote the following program:

package main

import (
    \"fmt\"
)

func processevents(list chan func()) {
    for {
        //a := <-list
        //a()
         


        
3条回答
  •  感情败类
    2020-12-05 12:40

    Good news, since Go 1.2 (december 2013) the original program now works as expected. You may try it on Playground.

    This is explained in the Go 1.2 release notes, section "Pre-emption in the scheduler" :

    In prior releases, a goroutine that was looping forever could starve out other goroutines on the same thread, a serious problem when GOMAXPROCS provided only one user thread. In Go 1.2, this is partially addressed: The scheduler is invoked occasionally upon entry to a function.

提交回复
热议问题