Documentation
¶
Overview ¶
Package goid tells goroutines apart. Go gives no way to ask for the number of the running goroutine, so there are two ways to tell them apart here:
- Token is what the framework compares on its hot paths (is this call from the UI goroutine? SPEC §13). On amd64 and arm64 it is the address of the runtime's record of the running goroutine (its "g"), read by a function in Go assembly in a nanosecond; on every other architecture it is ID.
- ID is the number of the goroutine, parsed from the header of runtime.Stack. It walks the stack: about 1.4 µs at a shallow depth and 30 µs and more at 200 frames. It is for messages (the goroutine numbers that a WrongThread error names), not for a path that runs for every widget or render object.
A token is unique among the goroutines that are alive. The runtime reuses the record of a goroutine that has ended, so a token must not be kept past the life of its goroutine: a new goroutine can have the token of a dead one.
Flutter: no counterpart (Dart has isolates, not goroutines)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ID ¶
func ID() uint64
ID is the number of the calling goroutine, read from runtime.Stack. It costs microseconds and grows with the depth of the stack; use Token to compare goroutines.
func Token ¶
func Token() uint64
Token is a value that tells the calling goroutine from every other goroutine that is alive. On amd64 and arm64 it is the address of the runtime's record of the goroutine (the "g" that the runtime keeps in a register or in thread local storage), read by a function in Go assembly (getg_amd64.s, getg_arm64.s) in about a nanosecond, at any stack depth. It is never 0.
The record belongs to the goroutine for its whole life and the runtime never frees it, but it hands it to a new goroutine after the first one ended: do not keep a token longer than its goroutine lives.
Flutter: no counterpart
Types ¶
This section is empty.