Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DebugGoroutines = os.Getenv("DEBUG_GOROUTINES") == "1"
Functions ¶
func ID ¶
func ID() uint64
ID returns goroutine id of the goroutine that calls it. It calls runtime.Stack with a large enough buffer to capture the entire trace.
Example ¶
package main import ( "fmt" "github.com/searKing/golang/go/runtime/goroutine" ) func main() { fmt.Printf("%d\n", goroutine.ID()) }
Output: 1
Types ¶
type Lock ¶
type Lock uint64
Lock represents a goroutine ID, with goroutine ID checked, that is whether GoRoutines of lock newer and check caller differ. disable when DebugGoroutines equals false
func NewLock ¶
func NewLock() Lock
NewLock returns a goroutine Lock, that checks whether goroutine of lock newer and check caller differ. Code borrowed from https://github.com/golang/go/blob/master/src/net/http/h2_bundle.go
Example ¶
package main import ( "fmt" "sync" "github.com/searKing/golang/go/runtime/goroutine" ) func main() { oldDebug := goroutine.DebugGoroutines goroutine.DebugGoroutines = true defer func() { goroutine.DebugGoroutines = oldDebug }() g := goroutine.NewLock() g.MustCheck() var wg sync.WaitGroup wg.Add(1) go func() { defer wg.Done() defer func() { if r := recover(); r != nil { fmt.Printf("panic recovered: %v\n", r) } }() g.MustCheck() // should panic }() wg.Wait() }
Output: panic recovered: running on the wrong goroutine
func (Lock) CheckNotOn ¶
Check whether caller's goroutine escape lock
func (Lock) MustCheckNotOn ¶
func (g Lock) MustCheckNotOn()
Click to show internal directories.
Click to hide internal directories.