aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata
diff options
context:
space:
mode:
authorJaden Weiss <[email protected]>2020-03-27 19:56:27 -0400
committerAyke <[email protected]>2020-05-09 01:08:56 +0200
commitb4815192a6cb05e79fe70487c1f303b1b6f92026 (patch)
treed4e8e78d2fba1a4e93f20929269fac13cab572cb /testdata
parentc54e1cc9557cf16636dd3099c1a6742fe3fed260 (diff)
downloadtinygo-b4815192a6cb05e79fe70487c1f303b1b6f92026.tar.gz
tinygo-b4815192a6cb05e79fe70487c1f303b1b6f92026.zip
testdata, sync: add sync.Mutex test to testdata/coroutines.go
Diffstat (limited to 'testdata')
-rw-r--r--testdata/coroutines.go28
-rw-r--r--testdata/coroutines.txt6
2 files changed, 33 insertions, 1 deletions
diff --git a/testdata/coroutines.go b/testdata/coroutines.go
index 77e14d0e0..49fdfc287 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 e296f8e0c..1e29558af 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