fengyoulin / goid

Get current goroutine's unique runtime ID.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

goid

Get current goroutine's ID, which is maintained by the golang runtime and can be used as an unique identifier for the goroutine.

Example:

package main

import (
	"fmt"
	"github.com/fengyoulin/goid"
	"sync"
)

const limit = 50

func main() {
	wg := sync.WaitGroup{}
	wg.Add(limit)

	for i := 0; i < limit; i++ {
		go func(idx int) {
			fmt.Printf("%d: %d\n", idx, goid.ID())
			wg.Done()
		}(i)
	}
	wg.Wait()
}

About

Get current goroutine's unique runtime ID.

License:MIT License


Languages

Language:Go 67.2%Language:C 20.6%Language:Assembly 12.2%