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
go version
go version go1.13 windows/amd64
go env
$ go env
func GetGoroutineID() uint64 { b := make([]byte, 1024) runtime.Stack(b, false) println(string(b)) b = bytes.TrimPrefix(b, []byte("goroutine ")) b = b[:bytes.IndexByte(b, ' ')] n, _ := strconv.ParseUint(string(b), 10, 64) return n } func main() { go func() { println(1, runTime.GetGoroutineID()) }() time.Sleep(1 * time.Second) go println(2, runTime.GetGoroutineID()) time.Sleep(1 * time.Second) println(3, runTime.GetGoroutineID()) time.Sleep(1 * time.Second) }
1,goroutineID1 2,goroutineID2 3,1
1,goroutineID1 2,1 3,1
More output details:
goroutine 5 [running]: SimpleGoRepo/src/runTime.GetGoroutineID(0x0) D:/GOPATH/src/SimpleGoRepo/src/runTime/routine_id.go:36 +0x85 main.main.func1() D:/GOPATH/src/SimpleGoRepo/main.go:186 +0x29 created by main.main D:/GOPATH/src/SimpleGoRepo/main.go:185 +0x40 1 5 goroutine 1 [running]: SimpleGoRepo/src/runTime.GetGoroutineID(0x3b9aca00) D:/GOPATH/src/SimpleGoRepo/src/runTime/routine_id.go:36 +0x85 main.main() D:/GOPATH/src/SimpleGoRepo/main.go:189 +0x52 2 1 goroutine 1 [running]: SimpleGoRepo/src/runTime.GetGoroutineID(0x3b9aca00) D:/GOPATH/src/SimpleGoRepo/src/runTime/routine_id.go:36 +0x85 main.main() D:/GOPATH/src/SimpleGoRepo/main.go:191 +0x8e 3 1
The text was updated successfully, but these errors were encountered:
https://play.golang.org/p/iPZaigoakwd its the same:
goroutine 5 [running]: main.GetGoroutineID(0x0, 0x0) /tmp/sandbox409247425/prog.go:12 +0x80 main.main.func1() /tmp/sandbox409247425/prog.go:22 +0x20 created by main.main /tmp/sandbox409247425/prog.go:21 +0x40
1 5 goroutine 1 [running]: main.GetGoroutineID(0x3b9aca00, 0x0) /tmp/sandbox409247425/prog.go:12 +0x80 main.main() /tmp/sandbox409247425/prog.go:25 +0x80
2 1 goroutine 1 [running]: main.GetGoroutineID(0x3b9aca00, 0x0) /tmp/sandbox409247425/prog.go:12 +0x80 main.main() /tmp/sandbox409247425/prog.go:27 +0x100
3 1
Sorry, something went wrong.
the arguments to the goroutine are evaluated before being passed to the function/goroutine,
in this case GetGoroutineID is being called from main, before the result is passed to println which is run in the goroutine
Working as expected.
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: