summaryrefslogtreecommitdiff
path: root/lib/thread
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-01-18 22:56:58 -0800
committerOri Bernstein <ori@eigenstate.org>2016-01-18 22:56:58 -0800
commitd8bd5599e0e4b7919e3987ad80cb39f4a8aff63d (patch)
tree492486e697c3754e3a006e2d07c8c64221d452e0 /lib/thread
parent74389e559a91db698364664797e3819302a15836 (diff)
downloadmc-d8bd5599e0e4b7919e3987ad80cb39f4a8aff63d.tar.gz
Add a broken spawn+osx.myr
It works under dtruss...
Diffstat (limited to 'lib/thread')
-rw-r--r--lib/thread/bld.proj6
-rw-r--r--lib/thread/spawn+osx.myr40
2 files changed, 46 insertions, 0 deletions
diff --git a/lib/thread/bld.proj b/lib/thread/bld.proj
index 56ee535..62cbd0b 100644
--- a/lib/thread/bld.proj
+++ b/lib/thread/bld.proj
@@ -14,6 +14,12 @@ lib thread =
spawn+freebsd.myr
exit+freebsd-x64.s
+ # osx impl of thread primitives
+ #condvar+osx.myr
+ #mutex+osx.myr
+ spawn+osx.myr
+ #exit+osx-x64.s
+
# 9front impl of thread primitives
#condvar+plan9.myr
mutex+plan9.myr
diff --git a/lib/thread/spawn+osx.myr b/lib/thread/spawn+osx.myr
new file mode 100644
index 0000000..3c2f391
--- /dev/null
+++ b/lib/thread/spawn+osx.myr
@@ -0,0 +1,40 @@
+use sys
+use std
+
+pkg thread =
+ type tid = uint64
+
+ const spawn : (fn : (-> void) -> std.result(tid, byte[:]))
+;;
+
+
+const Stacksz = 8*std.MiB
+extern const exit : (-> void)
+
+const spawn = {fn
+ -> spawnstk(fn, Stacksz)
+}
+
+const spawnstk = {fn, sz
+ var tid : tid, ret
+
+
+ ret = sys.bsdthread_create( \
+ startthread castto(void#), \
+ &fn castto(void#), \
+ sz castto(void#), \
+ &tid castto(void#), \
+ 0)
+
+ if ret == -1 castto(void#)
+ -> `std.Fail "couldn't spawn thread"
+ ;;
+ -> `std.Ok tid castto(tid)
+}
+
+const startthread = {fn : (-> void)# -> void
+ fn#()
+ std.write(1, "...bye mom\n")
+ sys.bsdthread_terminate(0 castto(void#), 0, 0, 0)
+}
+