Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: NumGoroutine is 2 in main when using -linkshared #16631

Closed
mwhudson opened this issue Aug 7, 2016 · 9 comments
Closed

runtime: NumGoroutine is 2 in main when using -linkshared #16631

mwhudson opened this issue Aug 7, 2016 · 9 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mwhudson
Copy link
Contributor

mwhudson commented Aug 7, 2016

Please answer these questions before submitting your issue. Thanks!

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

go version devel +219ca60 Sat Aug 6 19:30:57 2016 +0000 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/opt/opensource/gopath"
GORACE=""
GOROOT="/opt/opensource/go"
GOTOOLDIR="/opt/opensource/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build374916367=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

  1. What did you do?

go run run.go -linkshared goprint.go

  1. What did you expect to see?

no output but the process exiting cleanly

  1. What did you see instead?

it hangs

@mwhudson
Copy link
Contributor Author

mwhudson commented Aug 8, 2016

I'd previously said that this happened with 1.6 but it doesn't, this is a regression (sadface).

@mwhudson
Copy link
Contributor Author

mwhudson commented Aug 8, 2016

Ah so the good news is that this is because the test is a bit silly (in a way that it is not in 1.6). And this is the real 'problem':

$ cat numgoroutine.go
package main

import "runtime"

func main() {
    println(runtime.NumGoroutine())
}
$ go run numgoroutine.go 
1
$ go run -linkshared numgoroutine.go 
2

This difference is present in 1.6 so not a regression. I'll either try to figure out what's going on or just fix the test in early 1.8.

@quentinmit
Copy link
Contributor

@mwhudson Do we need to skip the test in 1.7?

@quentinmit quentinmit added this to the Go1.7Maybe milestone Aug 8, 2016
@mwhudson
Copy link
Contributor Author

mwhudson commented Aug 8, 2016

It's not run by default, so I'd say no.

@quentinmit quentinmit modified the milestones: Go1.7Maybe, Go1.8Maybe Aug 25, 2016
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 10, 2016
@rsc rsc changed the title test: go run run.go -linkshared goprint.go hangs on Ubuntu 16.04 runtime: NumGoroutine is 2 in main when using -linkshared Oct 21, 2016
@rsc rsc modified the milestones: Go1.9, Go1.8Maybe Nov 2, 2016
@aclements
Copy link
Member

@mwhudson, I probably just don't know what I'm doing here, but when I tried to reproduce this I get:

$ go run -linkshared main.go
# command-line-arguments
/home/austin/go.dev/pkg/tool/linux_amd64/link: cannot implicitly include runtime/cgo in a shared library

I tried go install -linkshared runtime first, but it didn't help.

@aclements aclements self-assigned this Jun 6, 2017
@mwhudson
Copy link
Contributor Author

mwhudson commented Jun 6, 2017

@aclements you need to run go install -buildmode=shared std first

@mwhudson
Copy link
Contributor Author

mwhudson commented Jun 6, 2017

Although the -linshared is probably irrelevant, it happens just when linking externally:

$ go run -ldflags='-linkmode=external' numgoroutine.go
2

@aclements
Copy link
Member

Thanks.

It looks like the "second" goroutine is the spare M used by cgo callbacks. So this will appear whenever cgo is used.

Perhaps that should be marked as a system goroutine until it's actually used...

@gopherbot
Copy link

CL https://golang.org/cl/45030 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants