It's a combination of :
1) A read and a write of a variable, happening without synchronization (see 
happens-before <https://golang.org/ref/mem#tmp_2>), is always a race, and 
always a bug, even when it "looks" innocuous.
2) When the receiver of a method is not a pointer, then this receiver is 
copied when the method is called.
3)  (*RPC) compute()  writes field result.
4)  (RPC) version()  copies the whole RPC value, which is a read to field 
result.

There is a data race on rpc.result

On Sunday, April 2, 2017 at 11:57:59 PM UTC+2, st ov wrote:
>
> Could you explain how this is a race condition?
> Running it in the playground appears to succeed, 
> https://play.golang.org/p/zs6T361fc6
>
>
>
>
> On Saturday, March 25, 2017 at 7:51:52 PM UTC-7, Dragos Harabor wrote:
>>
>> You may also run into subtle races when you mix pointer and value 
>> receivers, as seen here:
>> https://dave.cheney.net/2015/11/18/wednesday-pop-quiz-spot-the-race
>>
>>
>> On Friday, March 24, 2017 at 6:20:06 PM UTC-7, st ov wrote:
>>>
>>> Is it idiomatic to mix-&-match pointer and value method receivers for a 
>>> given type? 
>>> or in *general*, if a single method requires a pointer receiver than *all 
>>> methods* should take a pointer, regardless if a value receiver is 
>>> appropriate?
>>>
>>> For example, should Foo.SetVal also be a pointer receiver even though a 
>>> value receiver would be acceptable?
>>> https://play.golang.org/p/rd_6BLol8O
>>>
>>> type Foo struct{
>>>     ref []int
>>>     val int
>>> }
>>>
>>> // would not set if method receiver is value receiver (foo Foo)
>>> func (foo *Foo) SetRef(ref []int) {
>>>     foo.ref = ref
>>> }
>>> func (foo Foo) SetVal(val int) {
>>>     foo.val = val
>>> }
>>>
>>> func main() {
>>>     foo := Foo{}
>>>     foo.SetRef([]int{1,2,3})
>>>     foo.SetVal(1)
>>>     
>>>     fmt.Printf("%v",foo) // {[1 2 3] 0}
>>> }
>>>
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to