You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried a simple snippet to evaluate the mutex profile:
var mtx sync.Mutex
var wg sync.WaitGroup
func acquire(n time.Duration) {
mtx.Lock()
defer mtx.Unlock()
time.Sleep(n)
wg.Done()
}
func main() {
runtime.SetMutexProfileFraction(1)
wg.Add(5)
go acquire(1 * time.Second) // gowrap1
go acquire(2 * time.Second) // gowrap2
go acquire(3 * time.Second) // gowrap3
go acquire(4 * time.Second) // gowrap4
go acquire(5 * time.Second) // gowrap5
wg.Wait()
// Write mutex profile to file
f, err := os.Create("mutex.prof")
if err != nil {
log.Fatal(err)
}
defer f.Close()
if err := pprof.Lookup("mutex").WriteTo(f, 0); err != nil {
log.Fatal(err)
}
}
What did you see happen?
The order in which goroutines acquire the lock is: gowrap1 → gowrap5 → gowrap2 → gowrap3 → gowrap4. However, the result shows an overshoot in gowrap3's contention time and underestimates gowrap2:
What did you expect to see?
The expected contention time for gowrap2 should be 4 seconds. The contention time for gowrap3 should be 3 seconds. Not sure if this behavior is intentional.
The text was updated successfully, but these errors were encountered:
Go version
go1.23.9
Output of
go env
in your module/workspace:What did you do?
I tried a simple snippet to evaluate the mutex profile:
What did you see happen?
The order in which goroutines acquire the lock is:
gowrap1
→gowrap5
→gowrap2
→gowrap3
→gowrap4
. However, the result shows an overshoot ingowrap3
's contention time and underestimatesgowrap2
:What did you expect to see?
The expected contention time for
gowrap2
should be 4 seconds. The contention time forgowrap3
should be 3 seconds. Not sure if this behavior is intentional.The text was updated successfully, but these errors were encountered: