Why does sudog g field hold unsafe.Pointer?

92 views
Skip to first unread message

Mikhail Gritsenko

unread,
Jun 7, 2023, 8:13:59 AM6/7/23
to golang-nuts
Why does sudog struct for elem field for the second node in sendq of a chan hold unsafe.Pointer BUT the first node of the sendq holds actual value? Is it somehow related with sendDirect or this is just an address of a value that allocated on a stack of the sending goroutine?


image (6).png
image (5).png

Ian Lance Taylor

unread,
Jun 7, 2023, 2:47:11 PM6/7/23
to Mikhail Gritsenko, golang-nuts
On Wed, Jun 7, 2023 at 5:13 AM 'Mikhail Gritsenko' via golang-nuts
<golan...@googlegroups.com> wrote:
>
> Why does sudog struct for elem field for the second node in sendq of a chan hold unsafe.Pointer BUT the first node of the sendq holds actual value? Is it somehow related with sendDirect or this is just an address of a value that allocated on a stack of the sending goroutine?

Sorry, I'm not sure I understand the question. The sendq is just a
linked list of sudog structs. I'm not sure what you mean by the first
node. The elem field of a sudog is a pointer to the value being sent
on a channel (or a pointer to a place to put a value received from a
channel). That field is in the sudog so that the other end of the
channel can copy the value when performing a channel operation.

Ian
Reply all
Reply to author
Forward
0 new messages