[Solved] Unexpected behavior from launching a method call on a loop variable as a goroutine
Problem Your first version has a synchronisation bug, which manifests itself as a data race: $ go run -race main.go 0 (PrintAddr): 0xc0000b4018 0 (PrintAddr): 0xc0000c2120 ================== WARNING: DATA RACE Write at 0x00c0000b4018 by main goroutine: main.main() redacted/main.go:29 +0x1e5 Previous read at 0x00c0000b4018 by goroutine 7: main.(*User).PrintAddr() redacted/main.go:19 +0x44 Goroutine 7 (finished) created at: main.main() … Read more