GithubHelp home page GithubHelp logo

goroutine's Introduction

goroutine identification

Package goroutine provides functions that will return the runtime's ID number for the calling goroutine or its creator.

The implementation is derived from Laevus Dexter's comment in Gophers' Slack #darkarts, https://gophers.slack.com/archives/C1C1YSQBT/p1593885226448300 post which linked to this playground snippet https://play.golang.org/p/CSOp9wyzydP.

The code here is an exercise in minimalism, doing as little as possible by deferring nearly all of the logic to runtime functions co-opted via //go:linkname comments.

goroutine's People

Contributors

kortschak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

goroutine's Issues

performance profile

Just curious if you could make a basic performance profile to see how much penalty this calls incur, I can create one if that helps? thx

unclear docs

does this lib return the current goroutine id for the calling function? you say "runtime id" what does that mean?

Currently I am using this to retrieve the current gorotuine id:

func GetGID() uint64 {
	b := make([]byte, 64)
	b = b[:runtime.Stack(b, false)]
	b = bytes.TrimPrefix(b, []byte("goroutine "))
	b = b[:bytes.IndexByte(b, ' ')]
	n, _ := strconv.ParseUint(string(b), 10, 64)
	return n
}

but tmk this is not performant, so maybe this library does what I am looking for ... faster?

race tests fail after 1.18

Running race tests on go1.19+ gives small deltas between the expected and obtained goroutine number. For example on go1.20.

$  go test -race
--- FAIL: TestID (0.39s)
    gid_test.go:31: unexpected id for goroutine number 52758: got:52861 want:52810
FAIL
exit status 1
FAIL	github.com/kortschak/goroutine	0.410s

ref #7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.