question about HACKING.md

58 views
Skip to first unread message

Leah Stapleton

unread,
Jul 18, 2024, 2:28:07 PM (3 days ago) Jul 18
to golang-nuts
In the document HACKING.md (https://github.com/golang/go/blob/master/src/runtime/HACKING.md), it states that we can determine if we're running on the user or system stack by running `getg() == getg().m.curg`.

However if the output of that equality check is true, does that mean we're on user or system stack?

getg can return the current g but when executing on the system stack it returns the current M's g0. 

I assume that a true means we're on the user stack because it says "To get the current user g, use getg().m.curg". However, there's no where that I can see that says that m.curg can't be the system stack, so please clarify.



Thank you,



Ian Lance Taylor

unread,
Jul 18, 2024, 2:44:27 PM (3 days ago) Jul 18
to Leah Stapleton, golang-nuts
On Thu, Jul 18, 2024 at 11:29 AM Leah Stapleton
<leahstap...@gmail.com> wrote:
>
> In the document HACKING.md (https://github.com/golang/go/blob/master/src/runtime/HACKING.md), it states that we can determine if we're running on the user or system stack by running `getg() == getg().m.curg`.
>
> However if the output of that equality check is true, does that mean we're on user or system stack?

The user stack.

> getg can return the current g but when executing on the system stack it returns the current M's g0.
>
> I assume that a true means we're on the user stack because it says "To get the current user g, use getg().m.curg". However, there's no where that I can see that says that m.curg can't be the system stack, so please clarify.

As it says, getg().m.curg is the current user g. It's never a g0. A
g0 is never a user g. Each g has its own stack. A g0 has a fixed
system thread stack, a user g has a Go-managed user stack.

Ian
Reply all
Reply to author
Forward
0 new messages