On Thu, Apr 22, 2021 at 1:15 PM Mikhail Mazurskiy
<mikhail.mazur...@gmail.com> wrote:

> I stumbled upon this strange looking piece of code [1]. I thought it 
> dereferences the pointer, creating a copy of the mutex, and then calls 
> RLock() on the copy (i.e. a nop). But it does not work this way. I 
> experimented with it [2] and [3] and it looks like my reading of code is 
> wrong. Could someone explain how dereferencing a pointer works in this case 
> please? Language spec is not very explicit about it (unless I missed it) [4].

See https://golang.org/ref/spec#Selectors

""""
3. As an exception, if the type of x is a defined pointer type and
(*x).f is a valid selector expression denoting a field (but not a
method), x.f is shorthand for (*x).f.
""""

In this case '(*observer).Lock()' and 'observer.Lock()' have the same
semantics. Like here: https://play.golang.org/p/bPj-ZfPwRWc

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-UYzvz%3Dx%3Dk2gBzz37DHu6b-isXUZFoTpt9A%3DSLvACFiCQ%40mail.gmail.com.

Reply via email to