shithub: mc

Download patch

ref: d8bd5599e0e4b7919e3987ad80cb39f4a8aff63d
parent: 74389e559a91db698364664797e3819302a15836
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Jan 18 17:56:58 EST 2016

Add a broken spawn+osx.myr

    It works under dtruss...

--- a/lib/thread/bld.proj
+++ b/lib/thread/bld.proj
@@ -14,6 +14,12 @@
 	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
--- /dev/null
+++ b/lib/thread/spawn+osx.myr
@@ -1,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)
+}
+