Skip to content

Commit

Permalink
testdata, sync: add sync.Mutex test to testdata/coroutines.go
Browse files Browse the repository at this point in the history
  • Loading branch information
niaow authored and aykevl committed May 8, 2020
1 parent c54e1cc commit b481519
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
28 changes: 27 additions & 1 deletion testdata/coroutines.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import "time"
import (
"sync"
"time"
)

func main() {
println("main 1")
Expand Down Expand Up @@ -51,6 +54,29 @@ func main() {
println("closure go call result:", x)

time.Sleep(2 * time.Millisecond)

var m sync.Mutex
m.Lock()
println("pre-acquired mutex")
go acquire(&m)
time.Sleep(2 * time.Millisecond)
println("releasing mutex")
m.Unlock()
time.Sleep(2 * time.Millisecond)
m.Lock()
println("re-acquired mutex")
m.Unlock()
println("done")

time.Sleep(2 * time.Millisecond)
}

func acquire(m *sync.Mutex) {
m.Lock()
println("acquired mutex from goroutine")
time.Sleep(2 * time.Millisecond)
m.Unlock()
println("released mutex from goroutine")
}

func sub() {
Expand Down
6 changes: 6 additions & 0 deletions testdata/coroutines.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ async interface method call
slept inside func pointer 8
slept inside closure, with value: 20 8
closure go call result: 1
pre-acquired mutex
releasing mutex
acquired mutex from goroutine
released mutex from goroutine
re-acquired mutex
done

0 comments on commit b481519

Please sign in to comment.