You've already forked go-profiler-notes
mirror of
https://github.com/DataDog/go-profiler-notes.git
synced 2025-07-12 23:50:13 +02:00
split workloads
This commit is contained in:
35
bench/workload_mutex.go
Normal file
35
bench/workload_mutex.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func mutexWorkload(goroutines, ops, depth int) error {
|
||||
if goroutines%2 != 0 {
|
||||
return fmt.Errorf("bad goroutines: %d: must be a multiple of 2", goroutines)
|
||||
}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
for j := 0; j < goroutines/2; j++ {
|
||||
m := &sync.Mutex{}
|
||||
wg.Add(1)
|
||||
go atStackDepth(depth, func() {
|
||||
defer wg.Done()
|
||||
for i := 0; i < ops; i++ {
|
||||
m.Lock()
|
||||
m.Unlock()
|
||||
}
|
||||
})
|
||||
wg.Add(1)
|
||||
go atStackDepth(depth, func() {
|
||||
defer wg.Done()
|
||||
for i := 0; i < ops; i++ {
|
||||
m.Lock()
|
||||
m.Unlock()
|
||||
}
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user