Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions testdata/goroutines.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ func main() {
time.Sleep(2 * time.Millisecond)

var m sync.Mutex
var wg sync.WaitGroup
m.Lock()
println("pre-acquired mutex")
go acquire(&m)
wg.Add(1)
go acquire(&m, &wg)
time.Sleep(2 * time.Millisecond)
println("releasing mutex")
m.Unlock()
wg.Wait()
time.Sleep(2 * time.Millisecond)
m.Lock()
println("re-acquired mutex")
Expand All @@ -89,8 +92,9 @@ func main() {
<-done
}

func acquire(m *sync.Mutex) {
func acquire(m *sync.Mutex, wg *sync.WaitGroup) {
m.Lock()
wg.Done()
println("acquired mutex from goroutine")
time.Sleep(2 * time.Millisecond)
println("releasing mutex from goroutine")
Expand Down
Loading