github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zutil/runtime.go (about)

     1  package zutil
     2  
     3  import (
     4  	"bytes"
     5  	"runtime"
     6  	"strconv"
     7  )
     8  
     9  // GetGid Get coroutine id
    10  func GetGid() uint64 {
    11  	b := make([]byte, 64)
    12  	runtime.Stack(b, false)
    13  	b = bytes.TrimPrefix(b, []byte("goroutine "))
    14  	b = b[:bytes.IndexByte(b, ' ')]
    15  	n, _ := strconv.ParseUint(string(b), 10, 64)
    16  	return n
    17  }