Documentation ¶
Overview ¶
Package rt implements APIs for interacting with Go runtime.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GoID ¶
func GoID() (id uint64)
GoID returns the ID of current goroutine.
This implementation based on the facts that runtime.Stack gives information like:
goroutine 18446744073709551615 [running]: github.com/changkun/goid.Get...
This format stands for more than 10 years. Since commit 4dfd7fdde5957e4f3ba1a0285333f7c807c28f03, a goroutine id ends with a white space.
Go 1 compatability promise garantees all versions of Go can use this function.
Example ¶
package main import ( "fmt" "sort" "sync" "changkun.de/x/pkg/rt" ) func main() { cnums := make(chan int, 100) wg := sync.WaitGroup{} wg.Add(100) for i := 0; i < 100; i++ { go func() { cnums <- int(rt.GoID()) // down cast, wrong in large goid wg.Done() }() } wg.Wait() close(cnums) nums := []int{int(rt.GoID())} for v := range cnums { nums = append(nums, v) } sort.Ints(nums) fmt.Printf("%v", nums) }
Output:
Types ¶
type GCSignal ¶
type GCSignal struct {
// contains filtered or unexported fields
}
GCSignal is a signal that allows you to receive a notification after GC cycle
func NewGCSignal ¶
func NewGCSignal() *GCSignal
NewGCSignal creates a GC signal for the complextion of GC cycle.
Click to show internal directories.
Click to hide internal directories.