On Tue, Jun 8, 2021 at 12:08 PM Ian Davis <
m...@iandavis.com> wrote:
> When a method with a non-pointer receiver is called, is the copy made atomically? My intuition says it must be but perhaps someone else can confirm it?
I don't think the specs require that and I don't think well known
implementations try to enforce it. Also, above machine words it gets
complicated.
> If so, how does it work?
The receiver of a method is just the first parameter of an otherwise
ordinary function. I believe it's passed as any other argument,
currently by pushing it to the stack by the caller in case of gc, for
example. gccgo may already use registers, but that I'm only guessing.
(C ABI usually uses registers, but Go with gccgo may differ.)
FTR: AFAICT, from the perspective of the method, its receiver is
passed always by value, regardless if the method is declared on a
pointer receiver or not because a pointer is also a quite normal
value.