From b4815192a6cb05e79fe70487c1f303b1b6f92026 Mon Sep 17 00:00:00 2001 From: Jaden Weiss Date: Fri, 27 Mar 2020 19:56:27 -0400 Subject: [PATCH] testdata, sync: add sync.Mutex test to testdata/coroutines.go --- testdata/coroutines.go | 28 +++++++++++++++++++++++++++- testdata/coroutines.txt | 6 ++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/testdata/coroutines.go b/testdata/coroutines.go index 77e14d0e..49fdfc28 100644 --- a/testdata/coroutines.go +++ b/testdata/coroutines.go @@ -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() { diff --git a/testdata/coroutines.txt b/testdata/coroutines.txt index e296f8e0..1e29558a 100644 --- a/testdata/coroutines.txt +++ b/testdata/coroutines.txt @@ -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