(* Step 4: the macOS shape. The game owns the main thread; the compiler and the listener run beside it. The question is NOT "can OCaml use threads" -- it is whether caml_startup can be called from a pthread that C spawned, while main() goes on to run a window loop it never returns from. That is the inversion item 11 settles on, and it is the one that has to be measured rather than assumed. *) let compile file = let l = Flan.Load.program ~file (Flan.Parse.program (Flan.Reader.read_file file)) in let p = Flan.Check.program l.Flan.Load.decls in String.length (Flan.Emit.program ~dev:true p) let () = Callback.register "spike_thread_compile" (fun (file : string) -> let tid = Thread.id (Thread.self ()) in match compile file with | n -> Printf.sprintf "compiled on OCaml thread %d: %d bytes of LLVM IR" tid n | exception e -> Printf.sprintf "FAILED: %s" (Printexc.to_string e)); Callback.register "spike_domains" (fun () -> (* A second domain doing real work while the main thread is elsewhere -- 5.2's multicore runtime, which is the objection item 12 says has gone away. Confirmed rather than assumed. *) let d = Domain.spawn (fun () -> let s = ref 0 in for i = 1 to 5_000_000 do s := !s + i done; (Domain.self () :> int), !s) in let id, s = Domain.join d in Printf.sprintf "domain %d summed to %d; recommended_domain_count = %d" id s (Domain.recommended_domain_count ()))