summaryrefslogtreecommitdiff
path: root/lib/thread/test/tls.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/thread/test/tls.myr')
-rw-r--r--lib/thread/test/tls.myr49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/thread/test/tls.myr b/lib/thread/test/tls.myr
new file mode 100644
index 0000000..fa11111
--- /dev/null
+++ b/lib/thread/test/tls.myr
@@ -0,0 +1,49 @@
+use std
+use sys
+use thread
+
+const Nelt = 100
+const Nthr = 100
+
+var elts : thread.tid[Nelt]
+var start
+var wg
+
+const setget = {
+ var tid = thread.tid()
+ var localelts : thread.tid[Nelt]
+ for var i = 0; i < Nelt; i++
+ localelts[i] = elts[i] + tid
+ ;;
+
+ var k = start
+ for var i = 0; i < Nelt; i++
+ thread.tlsset(k, &localelts[i])
+ k++
+ ;;
+ k = start
+ for var i = 0; i < Nelt; i++
+ std.assert(thread.tlsget(k)# == localelts[i], "tls is broken\n")
+ k++
+ ;;
+ thread.wgpost(&wg)
+}
+
+const main = {
+ for var i = 0; i < Nelt; i++
+ elts[i] = std.randnum()
+ ;;
+
+ start = thread.tlsalloc()
+ for var i = 1; i < Nelt; i++
+ var k : thread.tlskey(thread.tid#) = thread.tlsalloc()
+ ;;
+
+ wg = thread.mkwg(Nthr)
+ for var i = 1; i < 100; i++
+ thread.spawn(setget)
+ ;;
+ setget()
+
+ thread.wgwait(&wg)
+}