Is it safe to access different struct members from different goroutines?
I understand that writing to the same variable without sync is dangareous:
package main
type Apple struct {
color string
size uint
}
func main() {
apple := &Apple{}
go func() {
apple.color = "red"
}()
go func() {
apple.color = "green"
}()
}
But can you write to different struct members without any kind of synchronization?
package main
type Apple struct {
color string
size uint
}
func main() {
apple := &Apple{}
go func() {
apple.color = "red"
}()
go func() {
apple.size = 42
}()
}
Or should I use chan
or sync.Mutex
for that?