Code snippet on playground
I am printing the pointer address for sync.WaitGroup
and they are all different. Why?
func Run() *sync.WaitGroup {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
fmt.Printf("goroutine %p
", &wg)
time.Sleep(5 * time.Second)
fmt.Println("wokeup")
}()
fmt.Printf("returning %p
", &wg)
return &wg
}
func main() {
runtime.GOMAXPROCS(3)
wg := Run()
fmt.Printf(" main %p
", &wg)
wg.Wait()
}
Typical output shows that the address is diff between that inside the function Run
and main
. I'd expect that to be the same, n'est-ce pas ?
returning 0xc0840045c0
main 0xc084000038
goroutine 0xc0840045c0
wokeup