testdata, sync: add sync.Mutex test to testdata/coroutines.go

This commit is contained in:
Jaden Weiss
2020-03-27 19:56:27 -04:00
committed by Ayke
parent c54e1cc955
commit b4815192a6
2 changed files with 33 additions and 1 deletions
+27 -1
View File
@@ -1,6 +1,9 @@
package main
import "time"
import (
"sync"
"time"
)
func main() {
println("main 1")
@@ -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() {
+6
View File
@@ -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