I'm trying to understand what happens when you make concurrent access to a pointers methods?
I have a map of pointers and spawn off a few go routines. I pass the map into each go routine and each go routine will use one of the values in the map. Nothing is being written to the map only being read from.
The map is small, only 4 keys so it's possible that more than one go routine will be using the same value from the map.
Question is, what happens when two go routines call a method of the same pointer? Will I get unpredictable results?
EDIT
Example: I'm taking out the map portion as that's not the question I'm after.
I have foo which is a pointer of type MyStruct and this structure has a method DoSomething that takes arguments. In the main function I'm creating two go routines and both of them make calls to foo.DoSomething passing different values. In this example the first go routine has a much larger calculation to preform than the second one (just using sleep times here to simulate calculations). Again nothing in the structure is changing I'm only making a call to the structures method. Do I have to worry about the second go routine making a call to foo.DoSomething when the first go routine is still working with the method?
package main
import (
"log"
"time"
)
type MyStruct struct {
}
func (self *MyStruct) DoSomething(value int) {
log.Printf("%d Start", value)
calculation_time := time.Duration(value) * time.Second
log.Printf("%d Calculating", value, calculation_time)
time.Sleep(calculation_time)
log.Printf("%d Done", value)
}
func main() {
var foo = new(MyStruct)
go foo.DoSomething(5)
// is this method call a problem when the first one is still working?
go foo.DoSomething(2)
time.Sleep(time.Duration(6 * time.Second))
}