On Thu, 22 Apr 2021 at 21:27, Jan Mercl <0xj...@gmail.com> wrote:

> 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
>

Thanks for the response, I didn't see this section. However, I'm still
confused as it says the exception in 3. only applies to fields, not to
methods. RLock() is obviously a method, not a field.

-- 
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/CALaYgJUZAxOJ8PSFrZ%3D%2BxBqvaD47UmOGCY_Bmfjk7JTqpYxSXw%40mail.gmail.com.

Reply via email to