summaryrefslogtreecommitdiff
path: root/lib/thread/spawn+plan9.myr
blob: 2c6e856a346b76c8df1d903672003af4316f8481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.Fail "unable to spawn thread"
	| thr:	-> `std.Ok (thr : tid)
	;;
}