Skip to content

Question: Is a chain of goroutines with empty select deletable? #36214

Closed
@anqur

Description

@anqur

What version of Go are you using (go version)?

$ go version
go version go1.13.5 windows/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOOS=windows

What did you do?

The following code shows that the chain of goroutines A and B remains and intuitively I think they can be removed from the scheduler. Is this necessary to remove them or any reason that removing is not a good choice or that's just not a deal?

package main

import (
	"fmt"
	"runtime"
	"time"
)

func B() {
	select {}
}

func A() {
	B()
}

func main() {
	go A()
	for i := 0; i < 20; i++ {
		time.Sleep(1 * time.Second)
		fmt.Println(runtime.NumGoroutine())
	}
}

What did you expect to see?

1
1
...

What did you see instead?

2
2
...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions