rt

package
v0.0.0-...-b044761 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2022 License: MIT Imports: 2 Imported by: 0

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 GetFuncName

func GetFuncName(i interface{}) string

GetFuncName return the function name

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.

func (*GCSignal) Send

func (gc *GCSignal) Send(ch chan<- struct{})

Send sends a GC complextion signal to the given channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL