You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\kefaise\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\kefaise\go
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\kefaise\AppData\Local\Temp\go-build992843230=/tmp/go-build -gno-record-gcc-switches
What did you do?
I tried to call method which use goroutine on all elements of slice. It didn't work, so I tried four different variations:
Slice of values, receiver is by pointer
Slice of values, receiver is by value
Slice of pointers, receiver is by pointer
Slice of pointers, receiver is by value
Only slice of values, receiver is by pointer behave inconsistently. I am aware that calling goroutine inside loop requires copy of variables one will use inside it. However this may cause hard to find bugs when one change method to use pointer receiver, or start using goroutines inside method. Moreover goroutine is called in context of method, so one might expect that receiver is stable in closure, when he don't change it.
for _, txtValue := range textsValues {
txtValue.printPointer(&wg)
}
Is equivalent to
var txtValue textHandler
for i := 0; i < len(textsValues); i++ {
txtValue = textsValues[i]
txtValue.printPointer(&wg)
}
When you take the pointer of txtValue , for the entire loop, it will be the same variable. Thus by the time the goroutine printed the value, it changed to something else as it's further along the loop.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I tried to call method which use goroutine on all elements of slice. It didn't work, so I tried four different variations:
Only slice of values, receiver is by pointer behave inconsistently. I am aware that calling goroutine inside loop requires copy of variables one will use inside it. However this may cause hard to find bugs when one change method to use pointer receiver, or start using goroutines inside method. Moreover goroutine is called in context of method, so one might expect that receiver is stable in closure, when he don't change it.
Program to reproduce this behaviour:
https://play.golang.org/p/DK0IdNnZMk5
What did you expect to see?
Something similar to
What did you see instead?
The text was updated successfully, but these errors were encountered: