On Thu, Apr 22, 2021 at 1:15 PM Mikhail Mazurskiy
<
mikhail....@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