shithub: mc

ref: 3a5ddf0610add4ea0663c4bf2d7f569ac723ad81
dir: /lib/thread/spawn+plan9.myr/

View raw version
use std
use sys

pkg thread =
	type tid = uint64

	const spawn : (fn : (-> void) -> std.result(tid, byte[:]))
;;

const spawn = {fn
	match sys.rfork(sys.Rfproc | sys.Rfmem | sys.Rfnowait)
	| 0:
		fn()
		std.exit(0)
	| -1:	-> `std.Err "unable to spawn thread"
	| thr:	-> `std.Ok (thr : tid)
	;;
}